package com.zprmb.udzt.activity;


import android.app.KeyguardManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.RequiresApi;
import android.support.v4.hardware.fingerprint.FingerprintManagerCompat;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.zprmb.udzt.BaseActivity;
import com.zprmb.udzt.BbtApplication;
import com.zprmb.udzt.Investcoupon;
import com.zprmb.udzt.LoginActivity;
import com.zprmb.udzt.PayActivity;
import com.zprmb.udzt.R;
import com.zprmb.udzt.V4WebViewRegisterActivity;
import com.zprmb.udzt.V6FingerPayPwdConfirmActivity;
import com.zprmb.udzt.V6LoginActivity;
import com.zprmb.udzt.V6ResultFinsh;
import com.zprmb.udzt.V6WebviewChild;
import com.zprmb.udzt.WebViewActivity;
import com.zprmb.udzt.bean.GetInvestInfo;
import com.zprmb.udzt.bean.JiaoYanBean;
import com.zprmb.udzt.bean.JiaoYanFailBean;
import com.zprmb.udzt.bean.LimitBean;
import com.zprmb.udzt.bean.YuePaySuccess;
import com.zprmb.udzt.http.AjaxParams;
import com.zprmb.udzt.util.Constant;
import com.zprmb.udzt.util.CustomDialog;
import com.zprmb.udzt.util.CustomDialog_view;
import com.zprmb.udzt.util.FingerSetting;
import com.zprmb.udzt.util.FingerprintUtil;
import com.zprmb.udzt.util.GuideAlertDialog;
import com.zprmb.udzt.util.GuideAlertDialog.OnSureClickListener;
import com.zprmb.udzt.util.LogUtils;
import com.zprmb.udzt.util.MySharePreferenceUtil;
import com.zprmb.udzt.util.NewVolleryUtil;
import com.zprmb.udzt.util.NumUtil;
import com.zprmb.udzt.util.Regular;
import com.zprmb.udzt.util.ToastUtil;
import com.zprmb.udzt.util.VolleryUtil;
import com.zprmb.udzt.util.VolleryUtil3;
import com.zprmb.udzt.util.VoteCalculator;

import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;

import static com.zprmb.udzt.R.id.v6_coupon_name;


public class V6iNewInvestCoupActivity2 extends BaseActivity implements OnClickListener, OnSureClickListener {
    //    private AddAndSubView addAndSubView;
    private RelativeLayout rl_back;
    private TextView tv_title;
    private TextView tv_availableAmount, tv_dexterityyue, tv_product_remainamount;
    private TextView tv_min_increaseNum;
    private String name, type, loanid, mytype;
    private TextView check_mAgreement;
    private RelativeLayout rl_use_coupon;
    private String reward_id;//礼券id
    private DecimalFormat df = new DecimalFormat("###0.00");
    private String red_type = ""; //红包类型
    private int ischange = 0;
    private Double availableGiftAmount = 0.0;//用户红包总量
    private Double coupon_rate = 0.0, red_rate = 0.0;//加息券利率 红包利率
    private TextView coupon_num;//加息券所剩张数
    private TextView coupon_name;//加息券名字
    private int month;
    private Double rate;
    private CheckBox check_dexterity;
    private TextView tv_add_money;
    private boolean use_status = false;
    private String flagFresh;
    private SharedPreferences sha;
    private Double availableAmount = 0.0;
    int avaiableAmount2 = 0;
    String avaiableAmount3;
    private TextView tv_product_shouyi;
    int minAmount = 0;
    private boolean finger_Count = false;
    private ImageView img_ck_status;
    private LinearLayout li_tishi;
    private DecimalFormat df2 = new DecimalFormat("###0");
    private Double maxAmount;
    int remainAmount = 0;
    private boolean payPass = true;
    private Double curAmount = 0.0, maxcurAmount = 0.0;
    private boolean nameauth = true, islogin = true;
    protected int increaseNum;
    private CheckBox check;
    private boolean ishuo;
    protected boolean tishi_coupon = true;
    protected boolean resultcoupon = false;
    private TextView tv_tishi;
    private TextView tv_mAgreement;
    private Button btn_invest;
    private boolean flagred;
    private RelativeLayout rl_dexterity;
    private int coupon_max, coupon_min;
    private int useFundAmountInvestFlag = 1;//特权时间
    private String firstType = "";
    private CustomDialog_view.Builder builder;
    private CustomDialog.Builder mDialog;
    String firstamount = "";
    private GuideAlertDialog mAlertDialog;

    //	private Double proportion;//项目利息availableAmount=63688442.95

    private TextView text_coupon;
    //抵扣的布局
    private LinearLayout layout_dikou;
    //抵扣金额
    private TextView text_dikou;
    //实际金额
    private TextView text_shiji;
    //title
    private int remainAmount2 = 0;
    private TextView text_title;
    //礼券布局
    private LinearLayout layout_liquan;
    int intentpaymoney = 0;
    KeyguardManager keyguardManager = (KeyguardManager) BbtApplication.getContext().getSystemService(BbtApplication.getContext().KEYGUARD_SERVICE);

    //余额全投

    LinearLayout layout_investall;
    TextView text_yue;

    TextView text_quantou;

    //输入的钱数

    EditText edit_zhitoumoney;

    TextView tv_v6_dexterity_pay_in_keyong;

    //清理输入框数据

    ImageView iv_cleardadta;
    LinearLayout layout_clear;
    TextView text_yuji;
    //清除布局
    String money_invest = "";

    //提示布局
    LinearLayout layout_tishi;

    LinearLayout li_all;
    static V6iNewInvestCoupActivity2 ActivityA;
    public static V6iNewInvestCoupActivity2 instance = null;

    //提示语
    TextView tv_v6_dexterity_pay_in_daotime;

    //抵扣券不满足的时候显示
    TextView text_dikou_buxianshi;
//抵扣券不满足时候呢

    TextView text_dikouquan_buman;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.invest_activity_beifen2);
        instance = this;
        setImmersionStatus();
        setContentInview(V6iNewInvestCoupActivity2.this).setVisibility(View.INVISIBLE);
        initIntent();
        Log.d("指纹的呢", getisFingerPay() + "");
        mAlertDialog = new GuideAlertDialog(this, this);
        tv_title = (TextView) findViewById(R.id.tv_title);
        rl_back = (RelativeLayout) findViewById(R.id.rl_back);
        text_coupon = (TextView) findViewById(R.id.text_coupon);
        //提示
        layout_tishi = (LinearLayout) findViewById(R.id.layout_tishi);
        //全部布局
        li_all = (LinearLayout) findViewById(R.id.li_all);
        li_all.setOnClickListener(this);
        li_all.performClick();
        tv_v6_dexterity_pay_in_daotime = (TextView) findViewById(R.id.tv_v6_dexterity_pay_in_daotime);
        initView();
        rl_back.setOnClickListener(this);
        registerBoradcastReceiver();
        layout_dikou = (LinearLayout) findViewById(R.id.layout_dikou);
        //抵扣金额
        text_dikou = (TextView) findViewById(R.id.text_dikou);
        //实际金额
        text_shiji = (TextView) findViewById(R.id.text_shiji);
        layout_dikou.setVisibility(View.GONE);
        //折扣券的产品
        text_title = (TextView) findViewById(R.id.text_title);
        text_title.setVisibility(View.GONE);
        layout_investall = (LinearLayout) findViewById(R.id.layout_investall);
        layout_investall.setOnClickListener(this);
        text_yue = (TextView) findViewById(R.id.text_yue);
        text_quantou = (TextView) findViewById(R.id.text_quantou);
        edit_zhitoumoney = (EditText) findViewById(R.id.edit_zhitoumoney);
        tv_v6_dexterity_pay_in_keyong = (TextView) findViewById(R.id.tv_v6_dexterity_pay_in_keyong);
        iv_cleardadta = (ImageView) findViewById(R.id.iv_cleardadta);
        iv_cleardadta.setOnClickListener(this);
        layout_liquan = (LinearLayout) findViewById(R.id.layout_liquan);
        text_yuji = (TextView) findViewById(R.id.text_yuji);
        layout_clear = (LinearLayout) findViewById(R.id.layout_clear);
        tv_title.setText(name);
        edit_zhitoumoney.requestFocus();
        text_dikou_buxianshi = (TextView) findViewById(R.id.text_dikou_buxianshi);
        text_dikouquan_buman = (TextView) findViewById(R.id.text_dikouquan_buman);
        if (TextUtils.isEmpty(edit_zhitoumoney.getText().toString())) {
//            btn_invest.setBackground(getResources().getDrawable(R.drawable.v6_ud_bg_gray));

            btn_invest.setEnabled(false);
            btn_invest.setBackgroundResource(R.drawable.v6greybutton);
            iv_cleardadta.setVisibility(View.GONE);
        }
        if (text_yuji.getText().toString().equals("0.00元")) {
            text_yuji.setTextColor(Color.parseColor("#757575"));

        }
        edit_zhitoumoney.setFocusable(true);

        edit_zhitoumoney.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (edit_zhitoumoney.getText().length() != 0) {
                    iv_cleardadta.setVisibility(View.VISIBLE);
                    btn_invest.setEnabled(true);
                    btn_invest.setBackgroundResource(R.drawable.v6button);
                    btn_invest.setTextColor(getResources().getColor(R.color.white));
                    try {

                        int b = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue();
                        if (b <= 0) {
                            text_shiji.setText("0.00");
                        }

                        DecimalFormat df = new DecimalFormat(
                                "######0.00");
                        double a = VoteCalculator
                                .getVoteCalculator_month_Dou(Double.valueOf(edit_zhitoumoney.getText().toString()), rate,
                                        month);
                        text_yuji.setText(df.format(a));
                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.VISIBLE);
//                    edit_zhitoumoney
                        int c = Integer.valueOf(dikou);
                        int d = b - c;
                        if (d <= 0) {
                            text_shiji.setText("0");
                        } else {
                            text_shiji.setText(String.valueOf(d));
                        }
                        if (b < coupon_max) {
                            text_coupon.setVisibility(View.VISIBLE);
                            layout_dikou.setVisibility(View.GONE);

                        } else {

                        }
                    } catch (Exception e) {
                    }
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                if (coupon_name.getText().toString().equals("未使用")) {
                                    layout_liquan.setVisibility(View.GONE);
                                    text_dikou_buxianshi.setVisibility(View.GONE);
                                }


                                if (TextUtils.isEmpty(edit_zhitoumoney.getText().toString())) {
                                    tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                    text_yuji.setText("投资金额不能为空");

                                    text_yuji.setTextColor(Color.parseColor("#ff0000"));
                                    btn_invest.setEnabled(false);
                                    btn_invest.setBackgroundResource(R.drawable.v6greybutton);

//                                        coupon_name.setText("未使用");


//预期收益那里
                                    text_yuji.setVisibility(View.VISIBLE);
                                    //预期收益那几个字
                                    tv_v6_dexterity_pay_in_daotime.setVisibility(View.VISIBLE);
                                    //投资限额那里
                                    text_dikouquan_buman.setVisibility(View.GONE);
//100元抵扣券那里text_title
                                    text_title.setVisibility(View.VISIBLE);
                                    //抵扣券那里的布局

                                    layout_dikou.setVisibility(View.VISIBLE);
                                    //抵扣券整体的布局
                                    layout_liquan.setVisibility(View.VISIBLE);
                                    tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                }

                                if (text_yuji.getText().toString().equals("0.00元")) {
                                    text_yuji.setTextColor(Color.parseColor("#757575"));


//预期收益那里
                                    text_yuji.setVisibility(View.VISIBLE);
                                    //预期收益那几个字
                                    tv_v6_dexterity_pay_in_daotime.setVisibility(View.VISIBLE);
                                    //投资限额那里
                                    text_dikouquan_buman.setVisibility(View.GONE);
//100元抵扣券那里text_title
                                    text_title.setVisibility(View.VISIBLE);
                                    //抵扣券那里的布局

                                    layout_dikou.setVisibility(View.VISIBLE);
                                    //抵扣券整体的布局
                                    layout_liquan.setVisibility(View.VISIBLE);
                                }
                                if (minAmount > remainAmount) {
                                    if (minAmount > remainAmount && Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() != remainAmount) {
                                        tishi_coupon = false;
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                        text_yuji.setText("投资金额必须为" + remainAmount + "");
                                        text_yuji.setTextColor(Color.parseColor("#ff0000"));


//预期收益那里
                                        text_yuji.setVisibility(View.VISIBLE);
                                        //预期收益那几个字
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.VISIBLE);
                                        //投资限额那里
                                        text_dikouquan_buman.setVisibility(View.GONE);
//100元抵扣券那里text_title
                                        text_title.setVisibility(View.VISIBLE);
                                        //抵扣券那里的布局

                                        layout_dikou.setVisibility(View.VISIBLE);
                                        //抵扣券整体的布局
                                        layout_liquan.setVisibility(View.VISIBLE);
                                        coupon_num.setVisibility(View.GONE);
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                    }
                                } else {
                                    if (Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() > remainAmount) {
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                        text_yuji.setText("投资金额已超剩余可投金额");
                                        text_yuji.setTextColor(Color.parseColor("#ff0000"));
                                        btn_invest.setEnabled(false);
                                        btn_invest.setBackgroundResource(R.drawable.v6greybutton);


//预期收益那里
                                        text_yuji.setVisibility(View.VISIBLE);
                                        //预期收益那几个字
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.VISIBLE);
                                        //投资限额那里
                                        text_dikouquan_buman.setVisibility(View.GONE);
//100元抵扣券那里text_title
                                        text_title.setVisibility(View.VISIBLE);
                                        //抵扣券那里的布局

                                        layout_dikou.setVisibility(View.VISIBLE);
                                        //抵扣券整体的布局
                                        layout_liquan.setVisibility(View.VISIBLE);
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                    } else if (!TextUtils.isEmpty(edit_zhitoumoney.getText().toString()) && Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() > maxAmount) {

                                        if (Double.valueOf(maxAmount).intValue() < 10000) {
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                            text_yuji.setText("投资金额已超" + Double.valueOf(maxAmount).intValue() + "元");
                                            text_yuji.setTextColor(Color.parseColor("#ff0000"));
                                            btn_invest.setEnabled(false);
                                            btn_invest.setBackgroundResource(R.drawable.v6greybutton);

//预期收益那里
                                            text_yuji.setVisibility(View.VISIBLE);
                                            //预期收益那几个字
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.VISIBLE);
                                            //投资限额那里
                                            text_dikouquan_buman.setVisibility(View.GONE);
//100元抵扣券那里text_title
                                            text_title.setVisibility(View.VISIBLE);
                                            //抵扣券那里的布局

                                            layout_dikou.setVisibility(View.VISIBLE);
                                            //抵扣券整体的布局
                                            layout_liquan.setVisibility(View.VISIBLE);
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                        } else {


//预期收益那里
                                            text_yuji.setVisibility(View.VISIBLE);
                                            //预期收益那几个字
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.VISIBLE);
                                            //投资限额那里
                                            text_dikouquan_buman.setVisibility(View.GONE);
//100元抵扣券那里text_title
                                            text_title.setVisibility(View.VISIBLE);
                                            //抵扣券那里的布局

                                            layout_dikou.setVisibility(View.VISIBLE);
                                            //抵扣券整体的布局
                                            layout_liquan.setVisibility(View.VISIBLE);
                                            int a = Double.valueOf(maxAmount).intValue() / 10000;
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                            text_yuji.setText("投资金额已超" + a + "万元");
                                            text_yuji.setTextColor(Color.parseColor("#ff0000"));
                                            btn_invest.setEnabled(false);
                                            btn_invest.setBackgroundResource(R.drawable.v6greybutton);
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);

                                        }


                                    }
                                    if (Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() < minAmount && coupon_name.getText().toString().contains("抵扣券")) {

                                        if (minAmount < 10000) {


//预期收益那里
                                            text_yuji.setVisibility(View.VISIBLE);
                                            //预期收益那几个字
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.VISIBLE);
                                            //投资限额那里
                                            text_dikouquan_buman.setVisibility(View.GONE);
//100元抵扣券那里text_title
                                            text_title.setVisibility(View.VISIBLE);
                                            //抵扣券那里的布局

                                            layout_dikou.setVisibility(View.VISIBLE);
                                            //抵扣券整体的布局
                                            layout_liquan.setVisibility(View.VISIBLE);
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                            text_yuji.setText(minAmount + "元起投");
                                            text_yuji.setTextColor(Color.parseColor("#ff0000"));
                                            btn_invest.setEnabled(false);
                                            btn_invest.setBackgroundResource(R.drawable.v6greybutton);
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                            text_title.setVisibility(View.GONE);
                                            layout_dikou.setVisibility(View.GONE);
                                        } else {
                                            int a = minAmount / 10000;


//预期收益那里
                                            text_yuji.setVisibility(View.VISIBLE);
                                            //预期收益那几个字
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.VISIBLE);
                                            //投资限额那里
                                            text_dikouquan_buman.setVisibility(View.GONE);
//100元抵扣券那里text_title
                                            text_title.setVisibility(View.VISIBLE);
                                            //抵扣券那里的布局

                                            layout_dikou.setVisibility(View.VISIBLE);
                                            //抵扣券整体的布局
                                            layout_liquan.setVisibility(View.VISIBLE);
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                            text_yuji.setText(a + "万元起投");
                                            text_yuji.setTextColor(Color.parseColor("#ff0000"));
                                            btn_invest.setEnabled(false);
                                            btn_invest.setBackgroundResource(R.drawable.v6greybutton);
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                        }


                                    }

                                    if (Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() < minAmount && coupon_name.getText().toString().contains("未使用")) {

                                        if (minAmount < 10000) {


//预期收益那里
                                            text_yuji.setVisibility(View.VISIBLE);
                                            //预期收益那几个字
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.VISIBLE);
                                            //投资限额那里
                                            text_dikouquan_buman.setVisibility(View.GONE);
//100元抵扣券那里text_title
                                            text_title.setVisibility(View.VISIBLE);
                                            //抵扣券那里的布局

                                            layout_dikou.setVisibility(View.VISIBLE);
                                            //抵扣券整体的布局
                                            layout_liquan.setVisibility(View.VISIBLE);
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                            text_yuji.setText(minAmount + "元起投");
                                            text_yuji.setTextColor(Color.parseColor("#ff0000"));
                                            btn_invest.setEnabled(false);
                                            btn_invest.setBackgroundResource(R.drawable.v6greybutton);
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                            text_title.setVisibility(View.GONE);
                                            layout_dikou.setVisibility(View.GONE);
                                        } else {
                                            int a = minAmount / 10000;


//预期收益那里
                                            text_yuji.setVisibility(View.VISIBLE);
                                            //预期收益那几个字
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.VISIBLE);
                                            //投资限额那里
                                            text_dikouquan_buman.setVisibility(View.GONE);
//100元抵扣券那里text_title
                                            text_title.setVisibility(View.VISIBLE);
                                            //抵扣券那里的布局

                                            layout_dikou.setVisibility(View.VISIBLE);
                                            //抵扣券整体的布局
                                            layout_liquan.setVisibility(View.VISIBLE);
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                            text_yuji.setText(a + "万元起投");
                                            text_yuji.setTextColor(Color.parseColor("#ff0000"));
                                            btn_invest.setEnabled(false);
                                            btn_invest.setBackgroundResource(R.drawable.v6greybutton);
                                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                        }


                                    } else if (Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() < Double.valueOf(touzijine).intValue() && myflag.equals("2") && coupon_name.getText().toString().contains("抵扣券")) {
                                        btn_invest.setEnabled(false);
                                        btn_invest.setBackgroundResource(R.drawable.v6greybutton);
                                        text_dikou_buxianshi.setVisibility(View.VISIBLE);
                                        text_dikou_buxianshi.setText(dikou_wenzi);
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                        edit_zhitoumoney.setSelection(edit_zhitoumoney.length());
                                        flagred = false;
                                        reward_id = "";
                                        red_type = "";
                                        coupon_rate = 0.0;
                                        use_status = true;
                                        tishi_coupon = true;
                                        resultcoupon = false;
                                        coupon_num.setText(couponCount + "张");
                                        coupon_num.setVisibility(View.GONE);
                                        dikou = "0";
//预期收益那里
                                        text_yuji.setVisibility(View.GONE);
                                        //预期收益那几个字
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                        //投资限额那里
                                        text_dikouquan_buman.setVisibility(View.VISIBLE);
//100元抵扣券那里text_title
                                        coupon_name.setVisibility(View.VISIBLE);
                                        text_title.setVisibility(View.GONE);
                                        //抵扣券那里的布局
                                        text_dikou_buxianshi.setVisibility(View.VISIBLE);
                                        layout_dikou.setVisibility(View.GONE);
                                        //抵扣券整体的布局
                                    } else if (!TextUtils.isEmpty(edit_zhitoumoney.getText().toString()) && Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() >= Double.valueOf(touzijine).intValue() && myflag.equals("2") && coupon_name.getText().toString().contains("抵扣券")) {
                                        btn_invest.setEnabled(true);
                                        btn_invest.setBackgroundResource(R.drawable.v6button);
                                        text_dikou_buxianshi.setText(dikou_wenzi);
                                        edit_zhitoumoney.setSelection(edit_zhitoumoney.length());
                                        flagred = false;
                                        reward_id = "";
                                        red_type = "";
                                        coupon_rate = 0.0;
                                        use_status = true;
                                        tishi_coupon = true;
                                        resultcoupon = false;
                                        coupon_name.setVisibility(View.VISIBLE);
//                rl_use_coupon.setVisibility(View.GONE);
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                        text_dikou_buxianshi.setVisibility(View.GONE);
//预期收益那里
                                        text_yuji.setVisibility(View.VISIBLE);
                                        //预期收益那几个字
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.VISIBLE);
                                        //投资限额那里
                                        text_dikouquan_buman.setVisibility(View.GONE);
//100元抵扣券那里text_title
                                        text_title.setVisibility(View.VISIBLE);
                                        //抵扣券那里的布局
                                        layout_dikou.setVisibility(View.VISIBLE);
                                        //抵扣券整体的布局
                                        layout_liquan.setVisibility(View.VISIBLE);
                                        text_dikouquan_buman.setVisibility(View.VISIBLE);
                                    } else if ((Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() - minAmount)
                                            % increaseNum != 0) {
//预期收益那里
                                        text_yuji.setVisibility(View.VISIBLE);
                                        //预期收益那几个字
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.VISIBLE);
                                        //投资限额那里
                                        text_dikouquan_buman.setVisibility(View.GONE);
//100元抵扣券那里text_title
                                        text_title.setVisibility(View.VISIBLE);
                                        //抵扣券那里的布局

                                        layout_dikou.setVisibility(View.VISIBLE);
                                        //抵扣券整体的布局
                                        layout_liquan.setVisibility(View.VISIBLE);
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                        text_yuji.setText("投资金额增量须为" + increaseNum + "的整数倍");
                                        text_yuji.setTextColor(Color.parseColor("#ff0000"));
                                        btn_invest.setEnabled(false);
                                        btn_invest.setBackgroundResource(R.drawable.v6greybutton);
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                    } else if (text_yuji.getText().toString().contains("亲") && Integer.valueOf(couponCount) > 0) {
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                    } else if (text_yuji.getText().toString().contains("元起投")) {
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                    } else if (text_yuji.getText().toString().contains("投资金额不能为空")) {
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                        text_yuji.setText("投资金额不能为空");
                                        text_yuji.setTextColor(Color.parseColor("#ff0000"));
                                        btn_invest.setEnabled(false);
                                        btn_invest.setBackgroundResource(R.drawable.v6greybutton);
                                    } else if (text_yuji.getText().toString().contains("投资金额增量须为")) {
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                    } else if (text_yuji.getText().toString().contains("投资金额已超")) {
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                    } else if (text_yuji.getText().toString().contains("投资金额必须为")) {
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                                    } else {
                                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.VISIBLE);
                                        text_yuji.setTextColor(Color.parseColor("#ff0000"));
                                    }
                                }


                            } catch (Exception e) {

                            }

                        }
                    }, 1000);


                } else {
                    iv_cleardadta.setVisibility(View.INVISIBLE);

                    btn_invest.setEnabled(false);
//                    btn_invest.setBackgroundResource(R.drawable.v6button);
//                    Toast.makeText(V6iNewInvestCoupActivity.this, "aaaaaaaa", Toast.LENGTH_SHORT).show();
                    btn_invest.setBackgroundResource(R.drawable.v6greybutton);
                }
            }
        });
        /**焦点变化监听**/
        edit_zhitoumoney.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View arg0, boolean arg1) {
                // TODO Auto-generated method stub
                if (edit_zhitoumoney.getText().length() != 0) {
                    //删除图标显示
                    iv_cleardadta.setVisibility(View.VISIBLE);
                } else {
                    //删除图标隐藏
                    iv_cleardadta.setVisibility(View.INVISIBLE);
                }
                if (arg1) {
                    //得到焦点
                } else {
                    //失去焦点，删除图标隐藏
                    iv_cleardadta.setVisibility(View.INVISIBLE);
                }
            }
        });
        //删除图标的点击监听事件
        iv_cleardadta.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // 执行清空EditText数据
                edit_zhitoumoney.setText("");

                tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                text_yuji.setText("投资金额不能为空");

                text_yuji.setTextColor(Color.parseColor("#ff0000"));
                btn_invest.setEnabled(false);
                btn_invest.setBackgroundResource(R.drawable.v6greybutton);
                edit_zhitoumoney.setSelection(edit_zhitoumoney.length());
                edit_zhitoumoney.setText("");
                tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);

                edit_zhitoumoney.setSelection(edit_zhitoumoney.length());
                flagred = false;
                reward_id = "";
                red_type = "";
                coupon_rate = 0.0;
                use_status = true;
                tishi_coupon = true;
                resultcoupon = false;
                coupon_num.setText(couponCount + "张");
//                couponCount
                coupon_num.setVisibility(View.VISIBLE);
//                rl_use_coupon.setVisibility(View.GONE);
                layout_liquan.setVisibility(View.GONE);
                dikou = "0";
                layout_liquan.setVisibility(View.INVISIBLE);
                coupon_name.setText("未使用");
                coupon_name.setTextColor(getResources().getColor(R.color.v6detail_backcolor));
                coupon_name.setVisibility(View.VISIBLE);
            }
        });
        layout_clear.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                edit_zhitoumoney.setText("");
                tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                edit_zhitoumoney.setSelection(edit_zhitoumoney.length());
                flagred = false;
                reward_id = "";
                red_type = "";
                coupon_rate = 0.0;
                use_status = true;
                tishi_coupon = true;
                resultcoupon = false;
                tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                text_yuji.setText("投资金额不能为空");

                text_yuji.setTextColor(Color.parseColor("#ff0000"));
                btn_invest.setEnabled(false);
                btn_invest.setBackgroundResource(R.drawable.v6greybutton);
                coupon_num.setText(couponCount + "张");
//                couponCount
                coupon_num.setVisibility(View.VISIBLE);
//                rl_use_coupon.setVisibility(View.GONE);
                layout_liquan.setVisibility(View.GONE);
                dikou = "0";
                layout_liquan.setVisibility(View.INVISIBLE);
                coupon_name.setText("未使用");
                coupon_name.setTextColor(getResources().getColor(R.color.v6detail_backcolor));
                coupon_name.setVisibility(View.VISIBLE);
            }
        });
        userinfo();
        inintData(1);

        try {
            if (MySharePreferenceUtil.get(V6iNewInvestCoupActivity2.this, "chanpin", "").equals("2")) {
                li_all.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        showPopupWindow2(li_all);
                    }
                }, 500);
            }
        } catch (Exception e) {

        }


    }


    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
//        inintData(0);
    }

    /*  hpay/v3/h5recharge
      String amount 充值金额
      String path 充值类型
      String card_no 银行卡号
      bank_name 银行编号
      String token
      String loan_id 产品ID
      String type 产品类型
      String investment_Amount 投资金额
      String coupon_id 道具id
      String coupon_type 道具类型*/


    String couponCount;
    //availableAmount  keyong

    //    remainamount ketou
    private void inintData(final int creat) {
        // TODO Auto-generated method stub
        VolleryUtil volleryUtil = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                setContentInview(V6iNewInvestCoupActivity2.this).setVisibility(View.VISIBLE);
                if (jsonObject.optInt("success") == 1) {
//					progressLayout.showContent();
                    LogUtils.e(V6iNewInvestCoupActivity2.this, "定期投资页面" + jsonObject.toString());
                    JSONObject json1 = jsonObject.optJSONObject("data");

                    if (json1 != null) {
                        JSONObject user = json1.optJSONObject("user");
                        JSONObject jsoncoupon = json1.optJSONObject("couponInfo");
                        rate = json1.optDouble("rate");
                        minAmount = json1.optInt("minAmount");
                        remainAmount = json1.optInt("remainAmount");
                        remainAmount2 = json1.optInt("minAmount");

                        maxAmount = json1.optDouble("maxAmount");
                        increaseNum = json1.optInt("increaseNum");
                        Log.d("zengliangz", increaseNum + "");
                        edit_zhitoumoney.setHint(remainAmount2 + "元起投" + "," + increaseNum + "元递增");
                        flagFresh = json1.optString("flagFresh");
                        if (user != null) {
                            check_dexterity.setEnabled(true);
                            rl_dexterity.setEnabled(true);
                            islogin = true;
                            d3 = user.optDouble("availableAmount");
//                            tv_product_remainamount.setText(NumUtil.getQiantwo(json1.optString("remainAmount")));
                            tv_availableAmount.setText(NumUtil.getQiantwo(user.optString("availableAmount")));

                            if (user.optInt("availableAmount") == 0) {
                                layout_investall.setEnabled(false);
                                text_yue.setEnabled(false);
                                text_quantou.setEnabled(false);
                                text_quantou.setTextColor(getResources().getColor(R.color.grew));
                                text_yue.setTextColor(getResources().getColor(R.color.grew));
                            }


                            tv_dexterityyue.setText(Regular.getDecimalFormatTwo(user.optDouble("curAmount")));
//							availableGiftAmount=user.optDouble("availableGiftAmount ");
                            availableAmount = user.optDouble("availableAmount");
                            avaiableAmount2 = user.optInt("availableAmount");
                            avaiableAmount3 = user.optString("availableAmount");
                            curAmount = user.optDouble("curAmount");
                            maxcurAmount = user.optDouble("maxTransferInvestAmount");
                            useFundAmountInvestFlag = user.optInt("useFundAmountInvestFlag");
                        } else {
                            check_dexterity.setEnabled(false);
                            rl_dexterity.setEnabled(false);
                            islogin = false;
                            tv_availableAmount.setText("0.00");
                            tv_dexterityyue.setText("0.00");
                            coupon_name.setText("登录查看");
                            coupon_num.setText("");


                        }
                        month = json1.optInt("days");
                      /*  if (creat == 1) {
                            addAndSubView.setNum(json1.optInt("minAmount"));
                        }*/
                        if (jsoncoupon != null) {
                            if (ischange == 2 && !sha.getString("check", "").equals("")) {

                            } else {
                                coupon_name.setTextColor(Color.parseColor("#64A6FE"));
                                coupon_name.setText(jsoncoupon.optString("couponMsg"));
                                if (!coupon_name.getText().toString().equals("登录查看")) {
                                    red_type = "";
                                    resultcoupon = false;
                                    coupon_num.setText(jsoncoupon.optString("couponCount") + "张");
                                    couponCount = jsoncoupon.optString("couponCount");
                                }
                            }
                        }
//剩余可投金额
                        tv_product_remainamount.setText(NumUtil.getQiantwo(json1.optString("remainAmount")));

                        tv_min_increaseNum.setText(df2.format(json1.optDouble("minAmount")) + "元起投," + json1.optString("increaseNum") + "元倍数递增");

//						addAndSubView.setMinnum(json1.optInt("minAmount"));
//                        addAndSubView.setincreaseNum(json1.optInt("increaseNum"));
                    }
                }
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub

            }
        };
        volleryUtil.setHeaders("token", getToken());
        volleryUtil.setRequestMethod(0);
        volleryUtil.setShow(true);
        volleryUtil.execute(V6iNewInvestCoupActivity2.this, Constant.URL + "/api/v6/render/assetDetail/" + type + "/" + loanid, "");
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (sha != null) {
                Editor editor = sha.edit();
                editor.clear();
                editor.commit();
            }
        }

        return super.onKeyDown(keyCode, event);
    }

    private void initView() {

        check = (CheckBox) findViewById(R.id.check);
        check_mAgreement = (TextView) findViewById(R.id.check_mAgreement);
        rl_dexterity = (RelativeLayout) findViewById(R.id.rl_dexterity);
//        addAndSubView.setTextSize(18);
        li_tishi = (LinearLayout) findViewById(R.id.li_tishi);
        tv_mAgreement = (TextView) findViewById(R.id.tv_mAgreement);
        sha = getSharedPreferences("coupon", MODE_PRIVATE);
        img_ck_status = (ImageView) findViewById(R.id.ck_status);
        tv_product_shouyi = (TextView) findViewById(R.id.tv_product_shouyi);
        tv_tishi = (TextView) findViewById(R.id.tv_tishi);
//        addAndSubView.setButtonBgResource(R.drawable.jiahao, R.drawable.jianhao);
        tv_availableAmount = (TextView) findViewById(R.id.tv_availableAmount);
        tv_dexterityyue = (TextView) findViewById(R.id.tv_dexterityyue);
        check_dexterity = (CheckBox) findViewById(R.id.check_dexterity);
        tv_product_remainamount = (TextView) findViewById(R.id.tv_product_remainamount);
        tv_min_increaseNum = (TextView) findViewById(R.id.tv_min_increaseNum);
        rl_use_coupon = (RelativeLayout) findViewById(R.id.rl_use_coupon);
        coupon_num = (TextView) findViewById(R.id.coupon_num);
        coupon_name = (TextView) findViewById(v6_coupon_name);
        tv_add_money = (TextView) findViewById(R.id.tv_add_money);
        btn_invest = (Button) findViewById(R.id.btn_invest);
        check_mAgreement.setOnClickListener(this);
        tv_mAgreement.setOnClickListener(this);
        btn_invest.setOnClickListener(this);
        tv_add_money.setOnClickListener(this);
        rl_use_coupon.setOnClickListener(this);
        rl_dexterity.setOnClickListener(this);
        check.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // TODO Auto-generated method stub
                if (isChecked) {
                    btn_invest.setEnabled(true);
                    btn_invest.setBackgroundResource(R.drawable.v6button);
                } else {
                    btn_invest.setEnabled(false);
                    btn_invest.setBackgroundResource(R.drawable.btn_unclick);
                }
            }
        });
        check_dexterity.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // TODO Auto-generated method stub
                if (isChecked) {
                    img_ck_status.setVisibility(View.VISIBLE);
                    check_dexterity.setChecked(true);
                } else {
                    img_ck_status.setVisibility(View.GONE);
                    check_dexterity.setChecked(false);
                }
                ishuo = isChecked;
//                myconmment();
            }
        });

    }

    Double d3 = 0.0;

    private void setImmersionStatus() {
        if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }

    private void incoupon() {
        if (!red_type.equals("")) {

            DecimalFormat df = new DecimalFormat(
                    "######0.00");
            double a = VoteCalculator
                    .getVoteCalculator_month_Dou(Double.valueOf(edit_zhitoumoney.getText().toString()), coupon_rate,
                            month);

            coupon_num.setText(Regular.setSpannablecolor("收益:" + df.format(a) + "元", "#cccccc", 0, 3));


        }
    }


    private void initIntent() {
        // TODO Auto-generated method stub
        name = getIntent().getStringExtra("name");
        type = getIntent().getStringExtra("type");
        mytype = getIntent().getStringExtra("type");
        loanid = getIntent().getStringExtra("id");
    }

    private void userinfo() {
        VolleryUtil vollery = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                if (jsonObject.optInt("success") == 1) {
                    JSONObject json1 = jsonObject.optJSONObject("data");
                    Gson gson = new Gson();

                    GetInvestInfo getInvestInfo = new GetInvestInfo();
                    getInvestInfo = gson.fromJson(jsonObject.toString(), GetInvestInfo.class);
//                    tv_product_remainamount.setText(Regular.getDecimalFormatTwo(Double.valueOf(getInvestInfo.getData().getRemainAmount())));
//                    tv_product_remainamount.setText(getInvestInfo.getData().getRemainAmount());
                    /*  if (json1 != null) {
                        JSONObject jsoncoupon = jsonObject.optJSONObject("couponInfo");
                        d3 = json1.optDouble("availableAmount");
                        tv_availableAmount.setText(Regular.getDecimalFormatTwo(json1.optDouble("availableAmount")));
                        tv_dexterityyue.setText(Regular.getDecimalFormatTwo(json1.optDouble("ltbAmount")));
                        tv_product_remainamount.setText(Regular.getDecimalFormatTwo(json1.optDouble("remainAmount")));
                        tv_min_increaseNum.setText(json1.optString("minAmount") + "元起投" + json1.optString("increaseNum") + "元倍数递增");
                        month = json1.optInt("days");
                        if (jsoncoupon != null) {
                            coupon_num.setText(jsoncoupon.optString("couponCount"));
                            coupon_name.setText(jsoncoupon.optString("couponMsg"));
                        }
                    }*/
                }
                LogUtils.e(V6iNewInvestCoupActivity2.this, jsonObject.toString());
//				ToJSON.initData2(jsonObject.toString(),"userinfo" );
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub

            }
        };
        vollery.setRequestMethod(0);
        vollery.setHeaders("token", getToken());

        vollery.execute(this, Constant.URL + "/api/v5/user/userInfo", "");
    }

    private void interest() {
        Log.e("计息", "开始计算");
        if (!red_type.equals("")) {
            if (Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() != 0) {
                if (red_type.equals("PERCENTAGE")) {
                    double redpage = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() * (0.005);
                    if (redpage > availableGiftAmount) {
                        redpage = availableGiftAmount;
                    }

                } else {
                    Log.e("num", Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() + "----" + month + "---" + Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() * (red_rate / 100) / 365 * month + "   " + red_rate);
                    double redpage = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() * (red_rate / 100) / 365 * month;
                    if (redpage > availableGiftAmount) {
                        redpage = availableGiftAmount;

                    }
                    Log.e("redpage", redpage + "" + availableGiftAmount);
                    coupon_num.setText(Regular.setSpannablecolor("收益:" + df.format(redpage), "#cccccc", 0, 3)
                            + "元");
                    Log.e("shouyi", coupon_num.getText().toString());

                }
            }
        }

    }

    String cardId, getIntentmoney, addtype, myflag = "0";
    String shijie = "0";
    String dikou = "0";
    String touzijine = "0";

    String dikou_wenzi = "";


    @Override
    protected void onActivityResult(int arg0, int arg1, Intent intent) {
        // TODO Auto-generated method stubx
        super.onActivityResult(arg0, arg1, intent);
        if (intent != null) {
            if (arg1 == 2) {
                addtype = intent.getStringExtra("add_type");
                myflag = intent.getStringExtra("my_flag");
                cardId = intent.getStringExtra("cardId");
                ischange = arg1;
                Log.d(myflag, "myflag3333333333333333");
                layout_liquan.setVisibility(View.GONE);

                if (myflag.equals("1")) {
                    flagred = true;
                    resultcoupon = false;
                    use_status = true;
                    tishi_coupon = false;
                    layout_dikou.setVisibility(View.GONE);
                    reward_id = intent.getStringExtra("id");
                    //红包
                    red_rate = Double.parseDouble(intent.getStringExtra("rate"));
                    red_type = intent.getStringExtra("red_type");
                    availableGiftAmount = Double.parseDouble(intent.getStringExtra("availableGiftAmount"));
                    Log.e("intent", availableGiftAmount + "");
                    Log.e("hongbaoid", reward_id + "");
                    Log.e("intentrate", intent.getStringExtra("rate") + "");
                    coupon_name.setTextColor(Color.parseColor("#cccccc"));
                    coupon_name.setText(intent.getStringExtra("name"));
                    coupon_name.setVisibility(View.VISIBLE);
                    text_coupon.setText("可用礼券");
                    coupon_num.setVisibility(View.VISIBLE);
                    text_title.setVisibility(View.GONE);
                    layout_dikou.setVisibility(View.GONE);
                    layout_liquan.setVisibility(View.GONE);

                    interest();
                    touzijine = intent.getStringExtra("touzijine");
//                    incoupon();
                    text_title.setVisibility(View.GONE);
                } else if (myflag.equals("2")) {
                    //抵扣券

                    layout_dikou.setVisibility(View.VISIBLE);
                    layout_liquan.setVisibility(View.VISIBLE);

                    flagred = false;
                    resultcoupon = true;
                    use_status = false;
                    tishi_coupon = false;
                    getIntentmoney = intent.getStringExtra("getMoney");
                    Log.d("333333333333", getIntentmoney);

                    reward_id = intent.getStringExtra("id");
                    red_type = intent.getStringExtra("red_type");
                    coupon_rate = Double.parseDouble(intent.getStringExtra("rate"));

                    coupon_name.setTextColor(Color.parseColor("#6bacfd"));
                    text_coupon.setText("可用福利");
                    coupon_name.setText(intent.getStringExtra("name"));
                    coupon_name.setVisibility(View.VISIBLE);
                    coupon_max = intent.getIntExtra("maxAmount", 0);
                    coupon_min = intent.getIntExtra("minAmount", 0);

//                    text_shiji.setText(String.valueOf(intentpaymoney));


                    coupon_num.setVisibility(View.GONE);
                    text_dikou.setText(intent.getStringExtra("zhekouMoney"));
                    dikou = intent.getStringExtra("zhekouMoney");

                    int a = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() - Integer.valueOf(dikou);
                    Log.e("55555555555555", dikou + "");
                    Log.e("55555555555555", a + "");
                    Log.d("55555555555555", edit_zhitoumoney.getText().toString() + "");

                    text_shiji.setText(a + "");

                    text_title.setText(intent.getStringExtra("zhekouMoney") + intent.getStringExtra("intentTitle"));
                    Log.d("333333333333", dikou);
                    coupon_name.setTextColor(Color.parseColor("#cccccc"));
                    touzijine = intent.getStringExtra("touzijine");
                    coupon_num.setVisibility(View.GONE);
                    incoupon();
                    text_title.setVisibility(View.VISIBLE);
                } else {
                    //加息券
                    flagred = false;
                    resultcoupon = true;
                    use_status = false;
                    tishi_coupon = false;
                    layout_dikou.setVisibility(View.VISIBLE);
                    reward_id = intent.getStringExtra("id");
                    red_type = intent.getStringExtra("red_type");
                    text_coupon.setText("可用礼券");
                    layout_liquan.setVisibility(View.GONE);

                    coupon_num.setVisibility(View.VISIBLE);
                    coupon_rate = Double.parseDouble(intent.getStringExtra("rate"));
                    coupon_name.setTextColor(Color.parseColor("#cccccc"));
//                    coupon_name.setVisibility(View.VISIBLE);
                    coupon_name.setText(intent.getStringExtra("name"));
                    Log.d("33333333333333333", intent.getStringExtra("name"));


                }
            } else if (arg1 == 1) {
                ischange = arg1;
                flagred = false;
                reward_id = "";
                red_type = "";
                coupon_rate = 0.0;
                use_status = true;
                tishi_coupon = true;
                resultcoupon = false;

                coupon_num.setVisibility(View.VISIBLE);

                layout_liquan.setVisibility(View.INVISIBLE);
                myflag = "0";
                coupon_name.setVisibility(View.VISIBLE);
                inintData(0);
            }
            if (arg1 == 5) {
                setResult(5, intent);
                finish();
            }

        }
    }

    private void checkUserInfo() {
        VolleryUtil volleryUtil = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                LogUtils.e(V6iNewInvestCoupActivity2.this, jsonObject.toString());
                Log.d("33333333333333", "333333333333333");

                JSONObject json = jsonObject.optJSONObject("data");
                if ("false".equals(json.optString("bindCard"))) {
                    mAlertDialog.show();
                    mAlertDialog.setText("请绑定银行卡");
                    mAlertDialog.setTitle("提示");
                    mAlertDialog.setType("bindcard");
                    mAlertDialog.setButtonCancel("稍后");
                    mAlertDialog.setButtonsure("去绑卡");

                    return;
                }
                if ("false".equals(json.optString("payPass"))) {
                    mAlertDialog.show();
                    mAlertDialog.setText("请设置交易密码");
                    mAlertDialog.setTitle("提示");
                    mAlertDialog.setType("password");
                    mAlertDialog.setButtonCancel("稍后");
                    mAlertDialog.setButtonsure("去设置交易密码");
                    return;
                }
                if ("false".equals(json.optString("isRiskAssessment"))) {
                    mAlertDialog.show();
                    mAlertDialog.setText("请进行风险测评");
                    mAlertDialog.setTitle("提示");
                    mAlertDialog.setType("ceping");
                    mAlertDialog.setButtonCancel("稍后");
                    mAlertDialog.setButtonsure("去风险测评");
                    return;
                } else if (getisFinger() == 1) {
//                    onFingerprintClick(1);
                } else {

//                    onFingerprintClick(1);
                }
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub

            }
        };

    }

    private void verityUser() {
        VolleryUtil vollery = new VolleryUtil() {


            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                if (jsonObject.optInt("success") == 1) {
                    Log.e("userinfo", jsonObject.toString());
                    JSONObject json = jsonObject.optJSONObject("data");
//					availableGiftAmount = json.optDouble("availableGiftAmount");
                    payPass = json.optBoolean("payPass");
                    Intent intent = null;


                    if (!json.optBoolean("isBindCard")) {
                        mAlertDialog.show();
                        mAlertDialog.setText("请绑定银行卡");
                        mAlertDialog.setTitle("提示");
                        mAlertDialog.setType("bindcard");
                        mAlertDialog.setButtonCancel("稍后");
                        mAlertDialog.setButtonsure("去绑卡");

                        return;
                    }

                    if ("NOTHING".equals(json.optString("riskKey"))) {
                        mAlertDialog.show();
                        mAlertDialog.setText("请进行风险测评");
                        mAlertDialog.setTitle("提示");
                        mAlertDialog.setType("ceping");
                        mAlertDialog.setButtonCancel("稍后");
                        mAlertDialog.setButtonsure("去风险测评");
                        return;
                    }


                    System.out.println("productdetails=rate===" + rate);
//					if (!json.optBoolean("payPass")) {
//						intent.putExtra("setPass", 1);
//					}


                } else {
                    if (jsonObject.optString("comment").equals("please login")) {


                        Intent intent = new Intent(V6iNewInvestCoupActivity2.this,
                                V6LoginActivity.class);
                        intent.putExtra("close", 1);
                        startActivity(intent);


                    } else {
                        ToastUtil.showCenterToast(V6iNewInvestCoupActivity2.this,
                                jsonObject.optString("comment"));
                    }
                }
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub

            }
        };
        vollery.setHeaders("token", getToken());
        vollery.setHeaders("client", "android");
        vollery.setShow(true);
        vollery.setRequestMethod(0);
        vollery.execute(V6iNewInvestCoupActivity2.this, Constant.URL
                + "/api/v5/user/userInfo", "");
    }

    /*
    * 实际多少元
    * */


    String flag_zhiwen = "1";

    public void onFingerprintClick(final int type) {
        FingerprintUtil.callFingerPrint(new FingerprintUtil.OnCallBackListenr() {
            @Override
            public void onSupportFailed() {
                showToast("当前设备不支持指纹");
            }

            @Override
            public void onInsecurity() {
                showToast("当前设备未处于安全保护中");
            }

            @Override
            public void onEnrollFailed() {
                showToast("请到设置中设置指纹");
            }

            @Override
            public void onAuthenticationStart() {
//                li_tishi.getVisibility()

                builder = new CustomDialog_view.Builder(V6iNewInvestCoupActivity2.this);

                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        FingerprintUtil.cancel();
                        builder.create().dismiss();
                        builder = null;
                        Intent intent = new Intent(V6iNewInvestCoupActivity2.this, PayActivity.class);
                        intent.putExtra("flagRedpack", flagred);
                        intent.putExtra("rate", rate);
                        intent.putExtra("qixian", month);
                        intent.putExtra("minAmount", minAmount);
                        intent.putExtra("isZhi", 0);
                        if (payPass) {
                            intent.putExtra("setPass", 0);
                        } else {
                            intent.putExtra("setPass", 1);
                            intent.putExtra("openfingerPay", 1);
                        }
                        intent.putExtra("flagFresh", flagFresh);
                        intent.putExtra("productId", loanid);
                        intent.putExtra("title_tpye", mytype);
                        intent.putExtra("increaseNum", increaseNum);
                        intent.putExtra("remainAmount", remainAmount);
                        intent.putExtra("myflag", myflag);

                        intent.putExtra("title", tv_title.getText().toString());

//                        getIntentmoney

                        try {
                            int myIntentMoney = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() - Integer.valueOf(dikou);
                            if (myflag.equals("2")) {
                                intent.putExtra("money", myIntentMoney + "");
                            } else {
                                intent.putExtra("money", edit_zhitoumoney.getText().toString() + "");
                                layout_liquan.setVisibility(View.INVISIBLE);
                                text_title.setVisibility(View.GONE);
                                layout_dikou.setVisibility(View.INVISIBLE);
                            }

                        } catch (Exception e) {

                        }

                        if (myflag.equals("1")) {
                            intent.putExtra("red_id", reward_id);
                        }

                        if (myflag.equals("2")) {
//                        intent.putExtra("money", shijie + "");
//                        intent.putExtra("money", myIntentMoney + "");
                            intent.putExtra("cardId", cardId);
                        } else {
                            intent.putExtra("raisingratesId", reward_id);
                            intent.putExtra("money", edit_zhitoumoney.getText().toString() + "");
                        }


                        intent.putExtra("flagcoupon", resultcoupon);
                        intent.putExtra("useCurrentAmountToInvest", ishuo);
                        startActivityForResult(intent, 0);


//                    V6iNewInvestCoupActivity.count = 0;
           /*         overridePendingTransition(R.anim.slide_in_from_bottom,
                            R.anim.slide_out_to_bottom);*/
                        overridePendingTransition(R.anim.right_in,
                                R.anim.right_in);
                    }
                });
                builder.setMessage("“优点智投”的 触控 ID");
                builder.setMessage2("请验证已有手机指纹");

//                builder.setMessage4("");
                builder.create().setCancelable(false);
                builder.create().show();


            }

            @Override
            public void onAuthenticationError(int errMsgId, CharSequence errString) {
                if (errMsgId == 7) {
                    verityUser();
                } else {
                    showToast(errString.toString());
                    Log.d("555555555555555", errString.toString());

                }
/*                if (builder.create() != null) {
                    builder.create().dismiss();
//                    builder = null;
                }*/

            }

            @Override
            public void onAuthenticationFailed() {

                showToast("再试一次");

                for (int i = 0; i < 1; i++) {

                    new V6iNewInvestCoupActivity2().method();
                }
                Log.d("方法一共被调用了", "" + V6iNewInvestCoupActivity2.count + "" + "次数");
            /*    MySharePreferenceUtil.put(V6iNewInvestCoupActivity.this, "touzi", count);
                String a = (String) MySharePreferenceUtil.get(V6iNewInvestCoupActivity.this, "zhitou", "");
                int c = Double.valueOf(a).intValue() + count;
*/
                Log.d("方法一共被调用了", "" + V6iNewInvestCoupActivity2.count_julu + "" + "次数");
                if (V6iNewInvestCoupActivity2.count > 3) {
                    Intent intent = new Intent(V6iNewInvestCoupActivity2.this, PayActivity.class);
                    intent.putExtra("flagRedpack", flagred);
                    intent.putExtra("rate", rate);
                    intent.putExtra("qixian", month);
                    intent.putExtra("minAmount", minAmount);
                    intent.putExtra("isZhi", 0);
                    if (payPass) {
                        intent.putExtra("setPass", 0);
                    } else {
                        intent.putExtra("setPass", 1);
                        intent.putExtra("openfingerPay", 1);
                    }
                    intent.putExtra("flagFresh", flagFresh);
                    intent.putExtra("productId", loanid);
                    intent.putExtra("title_tpye", mytype);
                    intent.putExtra("increaseNum", increaseNum);
                    intent.putExtra("remainAmount", remainAmount);
                    intent.putExtra("myflag", myflag);

                    intent.putExtra("title", tv_title.getText().toString());

//                        getIntentmoney

                    try {
                        int myIntentMoney = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() - Integer.valueOf(dikou);
                        if (myflag.equals("2")) {
                            intent.putExtra("money", myIntentMoney + "");
                        } else {
                            intent.putExtra("money", edit_zhitoumoney.getText().toString() + "");
                            layout_liquan.setVisibility(View.INVISIBLE);
                            text_title.setVisibility(View.GONE);
                            layout_dikou.setVisibility(View.INVISIBLE);
                        }

                    } catch (Exception e) {

                    }

                    if (myflag.equals("1")) {
                        intent.putExtra("red_id", reward_id);
                    }

                    if (myflag.equals("2")) {
//                        intent.putExtra("money", shijie + "");
//                        intent.putExtra("money", myIntentMoney + "");
                        intent.putExtra("cardId", cardId);
                    } else {
                        intent.putExtra("raisingratesId", reward_id);
                        intent.putExtra("money", edit_zhitoumoney.getText().toString() + "");
                    }


                    intent.putExtra("flagcoupon", resultcoupon);
                    intent.putExtra("useCurrentAmountToInvest", ishuo);
                    startActivityForResult(intent, 0);
                    FingerprintUtil.cancel();

                    builder.create().dismiss();
                    builder = null;
//                    V6iNewInvestCoupActivity.count = 0;
           /*         overridePendingTransition(R.anim.slide_in_from_bottom,
                            R.anim.slide_out_to_bottom);*/
                    overridePendingTransition(R.anim.right_in,
                            R.anim.right_in);
                } else if ((V6NewZhiTouDexterityPayInActivity.count + V6iNewInvestCoupActivity2.count) >= 5) {


                    Intent intent = new Intent(V6iNewInvestCoupActivity2.this, PayActivity.class);
                    intent.putExtra("flagRedpack", flagred);
                    intent.putExtra("rate", rate);
                    intent.putExtra("qixian", month);
                    intent.putExtra("minAmount", minAmount);
                    intent.putExtra("isZhi", 0);
                    if (payPass) {
                        intent.putExtra("setPass", 0);
                    } else {
                        intent.putExtra("setPass", 1);
                        intent.putExtra("openfingerPay", 1);
                    }
                    intent.putExtra("flagFresh", flagFresh);
                    intent.putExtra("productId", loanid);
                    intent.putExtra("title_tpye", mytype);
                    intent.putExtra("increaseNum", increaseNum);
                    intent.putExtra("remainAmount", remainAmount);
                    intent.putExtra("myflag", myflag);

                    intent.putExtra("title", tv_title.getText().toString());

//                        getIntentmoney

                    try {
                        int myIntentMoney = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() - Integer.valueOf(dikou);
                        if (myflag.equals("2")) {
                            intent.putExtra("money", myIntentMoney + "");
                        } else {
                            intent.putExtra("money", edit_zhitoumoney.getText().toString() + "");
                            layout_liquan.setVisibility(View.INVISIBLE);
                            text_title.setVisibility(View.GONE);
                            layout_dikou.setVisibility(View.INVISIBLE);
                        }

                    } catch (Exception e) {

                    }

                    if (myflag.equals("1")) {
                        intent.putExtra("red_id", reward_id);
                    }

                    if (myflag.equals("2")) {
//                        intent.putExtra("money", shijie + "");
//                        intent.putExtra("money", myIntentMoney + "");
                        intent.putExtra("cardId", cardId);
                    } else {
                        intent.putExtra("raisingratesId", reward_id);
                        intent.putExtra("money", edit_zhitoumoney.getText().toString() + "");
                    }


                    intent.putExtra("flagcoupon", resultcoupon);
                    intent.putExtra("useCurrentAmountToInvest", ishuo);
                    startActivityForResult(intent, 0);
//                    FingerprintUtil.cancel();
                    FingerprintUtil.cancel();

//                    FingerprintUtil.cancellationSignal.getCancellationSignalObject();

                    try {
                        builder.create().dismiss();
                        builder = null;

                    } catch (Exception e) {

                    }

//                    V6iNewInvestCoupActivity.count = 0;
           /*         overridePendingTransition(R.anim.slide_in_from_bottom,
                            R.anim.slide_out_to_bottom);*/
                    overridePendingTransition(R.anim.right_in,
                            R.anim.right_in);
                }

//                System.out.println("方法一共被调用了"+CountTheMethodExecute.count+"次");

            }

            @Override
            public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
//                showToast(helpString.toString());
                Log.d("444444444444444444", helpString.toString());


            }

            @Override
            public void onAuthenticationSucceeded(FingerprintManagerCompat.AuthenticationResult result) {
//                showToast("解锁成功");
                if (builder.create() != null) {
                    builder.create().dismiss();
                    if (type == 1) {

                        invest();

                    }
                } else {

                }
            }


        });
    }

    public static int count = 0;
    public static int count_julu = 0;

    public void method() {

        count++;
        count_julu++;


    }

    /**
     * 指纹投资
     */
    private void invest() {
        AjaxParams params = new AjaxParams();

        params.put("productType", type);
        params.put("productId", loanid);
//        params.put("amount", edit_zhitoumoney.getText().toString());
//        intent.putExtra("money", shijie + "");


        params.put("payType", "FINGERPRINT");
        params.put("useCurrentAmountToInvest", ishuo + "");

        if (myflag.equals("1")) {
            params.put("amount", edit_zhitoumoney.getText().toString() + "");
            params.put("giftId", reward_id);
        }

        if (myflag.equals("2")) {
            if (Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() < coupon_max) {
                params.put("amount", edit_zhitoumoney.getText().toString() + "");
            } else {
//                params.put("amount", shijie + "");

                int b = Integer.valueOf(dikou);
                int c = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() - b;
                params.put("amount", c + "");

            }
            params.put("cardId", cardId);

        } else if (myflag.equals("3")) {
            params.put("amount", edit_zhitoumoney.getText().toString() + "");
            params.put("raisingratesId", reward_id);
        } else {
            params.put("amount", edit_zhitoumoney.getText().toString() + "");
            params.put("cardId", cardId);
        }

        Log.e("投资", params.toString());


        VolleryUtil vollery = new VolleryUtil() {

            @Override
            public void onUpDate(final JSONObject jsonObject) {
                // TODO Auto-generated method stub
                Log.e("invest", jsonObject.toString());
                if (jsonObject.optInt("success") == 1) {
                    clearCoupon();

                    Log.e("invest", jsonObject.toString());

                    final JSONObject json1 = jsonObject.optJSONObject("data");

                    firstType = json1.optString("firstinvestType");
                    firstamount = json1.optString("ExperienceAmount");
                    if (json1.optBoolean("firstFlag")) {
                        firstType = "1";
                    } else {
                        firstType = "0";
                    }
//
//								if(MainActivity.instance!=null){
//									MainActivity.instance.finish();
//								}
                  /*  Intent intent = new Intent(V6iNewInvestCoupActivity.this, MainActivity.class);
                    intent.putExtra("submit", json1.optString("expectDueDate"));
//                    intent.putExtra("amount", addAndSubView.getNum() + "");
                    intent.putExtra("huo", 1);
                    intent.putExtra("url", "?isInvest=1&flagFresh=" + flagFresh + "&isFirstInvest=" + firstType + "&productType=" + "dq" + "&amount=" + edit_zhitoumoney.getText().toString() + "&action=1");
                    intent.putExtra("firstamount", firstamount);
                    intent.putExtra("firstType", firstType);
                    intent.putExtra("invest", 1);
                    intent.putExtra("useCurrentAmountToInvest", ishuo);
                    intent.putExtra("useCurrAmount", json1.optDouble("useCurrAmount"));
                    intent.putExtra("useFundAmount", json1.optDouble("useFundAmount"));
                    intent.putExtra("rate", json1.optString("count_rate_date"));
//								startActivityForResult(intent,1);
                    Editor editor = getShare().edit();
                    if (firstType.equals("1")) {
                        editor.putInt("firstType", 1);
                        editor.putString("active_url", "?isInvest=1&flagFresh=" + flagFresh + "&isFirstInvest=" + firstType + "&productType=" + "dq" + "&amount=" + edit_zhitoumoney.getText().toString() + "&action=1");
                    } else {
                        editor.putInt("firstType", 0);
                    }
                    editor.commit();
                    setResult(5, intent);
                    finish();*/

                    YuePaySuccess yuePaySuccess = new YuePaySuccess();
                    Gson gson = new Gson();
                    yuePaySuccess = gson.fromJson(jsonObject.toString(), YuePaySuccess.class);


                    Intent intent = new Intent(V6iNewInvestCoupActivity2.this, SuccessYueActivity.class);
                    intent.putExtra("active_url", yuePaySuccess.getData().getExpUrl());
                    intent.putExtra("title", tv_title.getText().toString());
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//收益到账
                    Long time = new Long(yuePaySuccess.getData().getExpectDueDate());
                    //起息日期
                    Long time2 = new Long(yuePaySuccess.getData().getCount_rate_date());
                    String d = format.format(time);
                    String e = format.format(time2);
                    intent.putExtra("qixi", e);

                    intent.putExtra("jieshu", d);
                    intent.putExtra("investmoney", yuePaySuccess.getData().getAmount());

                    startActivity(intent);
                    Intent mIntent = new Intent(ACTION_NAME);
                    mIntent.putExtra("yaner", "发送广播，相当于在这里传送数据");
                    //发送广播
                    sendBroadcast(mIntent);
                    Intent mIntent2 = new Intent(ACTION_NAME2);
                    mIntent2.putExtra("yaner", "发送广播，相当于在这里传送数据");
                    //发送广播
                    sendBroadcast(mIntent2);
                    finish();
//							}

                } else {
                    ToastUtil.showCenterToast(V6iNewInvestCoupActivity2.this,
                            jsonObject.optString("comment"));

                    if (jsonObject.optString("comment").equals(
                            "please login")) {
                        if (jsonObject.optString("comment").equals("please login")) {
                            Intent intent = new Intent(V6iNewInvestCoupActivity2.this,
                                    LoginActivity.class);
                            intent.putExtra("close", 1);
                            startActivity(intent);
//                            mpleaseLogin(V6iNewInvestCoupActivity.this,1,0,0);
                        }
                    }


                }
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub
                Intent intent = new Intent(V6iNewInvestCoupActivity2.this, V6ResultFinsh.class);
                intent.putExtra("title", "投资结果");

                intent.putExtra("description1", "您好，系统正在处理中，\n请3~5分钟之后前往 “我的账户-定期计划”");

                intent.putExtra("description2", "确认投资结果！若投资失败请重新操作");
                intent.putExtra("button", "我的账户");
                startActivity(intent);


            }
        };


        vollery.setShow(true);
        vollery.setRequestMethod(1);
        vollery.setHeaders("token", getToken());
        vollery.setHeaders("client", "android");
        vollery.setHeaders("deviceId", getdeviceId());
        vollery.setHeaders("deviceToken", getdevice_token());
        vollery.execute(this, Constant.URL
                + "api/v6/invest/invest?", params.toString());


    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        Log.e("删除键", "destroy");
        if (sha != null) {
            Editor editor = sha.edit();
            editor.clear();
            editor.commit();
        }
        Log.e("ondestroy", "ondestroy");
    }

    public void flagcoupon() {
        AjaxParams params = new AjaxParams();
        params.put("productId", loanid);
        //金额传实际支付的

//        params.put("amount", addAndSubView.getNum() + "");
        params.put("raisingratesId", reward_id);
        params.put("type", type);
        params.put("useCurrentAmountToInvest", ishuo + "");
        VolleryUtil volleryUtil = new VolleryUtil() {

            @Override
            public void onUpDate(JSONObject jsonObject) {
                // TODO Auto-generated method stub
                if (jsonObject.optInt("success") == 1) {
                    LogUtils.e("加息券校验", jsonObject.toString());

                    Log.d(jsonObject.toString(), "444444444444");


                } else {

                }
            }

            @Override
            public void onError() {
                // TODO Auto-generated method stub

            }
        };
        volleryUtil.setHeaders("token", getToken());
        volleryUtil.setHeaders("deviceId", getdeviceId());
        volleryUtil.setRequestMethod(1);
        volleryUtil.setShow(true);
        volleryUtil.execute(V6iNewInvestCoupActivity2.this, Constant.URL + "/api/v6/invest/invests/valid?", params.toString());
    }

    private void showDialog() {
        mDialog = new CustomDialog.Builder(V6iNewInvestCoupActivity2.this);
        mDialog.setMessage("优点智投上线指纹支付功能，是否开启使用？");
        mDialog.create().setCancelable(false);
        mDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

                mDialog.create().dismiss();
                Editor editor2 = getShare().edit();
                editor2.putInt("invest_num", getInvestNum() + 1);
                editor2.commit();
            }
        });
        mDialog.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                if (!keyguardManager.isKeyguardSecure()) {
                    mDialog.create().dismiss();
                    FingerSetting.openFingerPrintSettingPage(V6iNewInvestCoupActivity2.this);

                    return;
                }
                mStartActivity(V6iNewInvestCoupActivity2.this, V6FingerPayPwdConfirmActivity.class);
                mDialog.create().dismiss();

            }
        });
        mDialog.create().show();
    }

    String newProduceId;

    String path;
    String myamount = "0";
    String bank_name;
    String investment_Amount;
    String bankName;
    String card_no;
    String type2;
    String loan_id;
    String productId;

    String getBank_name;
    Double myamount2;
    String url;

    String limitByOnce;
    String limitByDay;
    String limitByMonth;

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent intent = null;
        switch (v.getId()) {
            case R.id.rl_back:
                Log.e("删除键", "rl_back");
                if (sha != null) {
                    Editor editor = sha.edit();
                    editor.clear();
                    editor.commit();
                }

                finish();
                break;
            case R.id.rl_use_coupon:
                if (coupon_name.getText().toString().equals("登录查看")) {
                    intent = new Intent(V6iNewInvestCoupActivity2.this,
                            V6LoginActivity.class);
                    intent.putExtra("close", 1);
                    startActivity(intent);
                    return;
                } else if (TextUtils.isEmpty(edit_zhitoumoney.getText().toString())) {


                    tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                    text_yuji.setText("投资金额不能为空");
                    text_yuji.setTextColor(Color.parseColor("#ff0000"));
                    btn_invest.setEnabled(false);
                    btn_invest.setBackgroundResource(R.drawable.v6greybutton);
                } else if (Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() == 0) {

                    tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                    text_yuji.setText("投资金额不能为0");
                    text_yuji.setTextColor(Color.parseColor("#ff0000"));
                    btn_invest.setEnabled(false);
                    btn_invest.setBackgroundResource(R.drawable.v6greybutton);
                } else {
                    intent = new Intent(V6iNewInvestCoupActivity2.this,
                            Investcoupon.class);
//			intent3.putExtra("rate", rate);
//			intent3.putExtra("month", month);
//			intent3.putExtra("money", et_money.getText().toString());
//			intent3.putExtra("red", availableGiftAmount);
                    intent.putExtra("isnew", false + "");
                    intent.putExtra("isred", false + "");
                    intent.putExtra("id", loanid);
                    intent.putExtra("flag", false + "");
                    intent.putExtra("type", type);

//                intent.putExtra("amount", addAndSubView.getNum());
                    intent.putExtra("amount", Double.valueOf(edit_zhitoumoney.getText().toString()).intValue());


                    startActivityForResult(intent, 0);
                    layout_tishi.setVisibility(View.GONE);
                }

                break;
            case R.id.tv_add_money:
                intent = new Intent(V6iNewInvestCoupActivity2.this,
                        V6WebviewChild.class);
                intent.putExtra("url", Constant.URL + "h5/account/recharge/view?app=true&token=");
                intent.putExtra("title", "智投宝");
                startActivity(intent);
                break;
            case R.id.btn_invest:

                if (coupon_name.getText().toString().equals("登录查看")) {
                    intent = new Intent(V6iNewInvestCoupActivity2.this,
                            V6LoginActivity.class);
                    intent.putExtra("close", 1);
                    intent.putExtra("web", 1);
                    startActivityForResult(intent, 1);
                    tishi_coupon = true;
                    return;
                }
                if (flagFresh.equals("true")) {
                    if (getisNewUser().equals("false")) {
                        li_tishi.setVisibility(View.VISIBLE);
                        tv_tishi.setText("该项目仅限新手投资");
                        layout_tishi.setVisibility(View.GONE);
                        return;
                    }
                    tishi_coupon = true;
                } else if (TextUtils.isEmpty(edit_zhitoumoney.getText().toString())) {
                    tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                    text_yuji.setText("投资金额不能为空");
                    text_yuji.setTextColor(Color.parseColor("#ff0000"));


                    layout_tishi.setVisibility(View.GONE);
                    tishi_coupon = true;
                } else if (minAmount > remainAmount) {
                    if (Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() != remainAmount) {
                        tishi_coupon = false;
                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                        text_yuji.setText("投资金额必须为" + remainAmount + "");
                        text_yuji.setTextColor(Color.parseColor("#ff0000"));
                    } else if (coupon_name.getText().toString().equals("未使用") && tishi_coupon && Integer.valueOf(couponCount) > 0) {
                        tishi_coupon = false;

                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                        text_yuji.setText("亲，您还有未使用的福利哦!");
                        text_yuji.setTextColor(Color.parseColor("#ff0000"));
                    } else {

                        AjaxParams params = new AjaxParams();
                        params.put("productId", loanid);
                        //金额传实际支付的

//                    int myIntentMoney = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() - Integer.valueOf(dikou);

                        if (myflag.equals("2")) {
                            int myIntentMoney = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() - Integer.valueOf(dikou);
                            params.put("amount", myIntentMoney + "");
                        } else {

                            params.put("amount", edit_zhitoumoney.getText().toString());
                        }
//                    params.put("amount", edit_zhitoumoney.getText().toString());
                        params.put("type", type);
                        params.put("useCurrentAmountToInvest", ishuo + "");

                        VolleryUtil volleryUtil = new VolleryUtil() {

                            @RequiresApi(api = VERSION_CODES.JELLY_BEAN)
                            @Override
                            public void onUpDate(JSONObject jsonObject) {
                                // TODO Auto-generated method stub
                                if (jsonObject.optInt("success") == 1) {
                                    LogUtils.e("加息券校验", jsonObject.toString());

                                    JiaoYanBean jiaoYanBean = new JiaoYanBean();
                                    Gson gson = new Gson();
                                    jiaoYanBean = gson.fromJson(jsonObject.toString(), JiaoYanBean.class);
                                    newProduceId = jiaoYanBean.getData().getProductId();
                                    Log.d(jsonObject.toString(), "444444444444");
                                    showPopupWindow(btn_invest);


                                } else if (jsonObject.optInt("success") == 0 && jsonObject.optString("comment").equals("please login")) {
                                    startActivity(new Intent(V6iNewInvestCoupActivity2.this, V6LoginActivity.class));
                                } else {
                                    JiaoYanFailBean jiaoYanFailBean = new JiaoYanFailBean();
                                    Gson gson = new Gson();
                                    jiaoYanFailBean = gson.fromJson(jsonObject.toString(), JiaoYanFailBean.class);
                                    JSONObject user = jsonObject.optJSONObject("data");

                                    myamount2 = user.optDouble("amount");


                                    path = jiaoYanFailBean.getData().getPath();
                                    myamount = jiaoYanFailBean.getData().getAmount();
                                    bank_name = jiaoYanFailBean.getData().getBankName();
                                    card_no = jiaoYanFailBean.getData().getCard_no();
                                    type2 = jiaoYanFailBean.getData().getType();
                                    loan_id = jiaoYanFailBean.getData().getLoan_id();
                                    productId = jiaoYanFailBean.getData().getProductId();
                                    getBank_name = jiaoYanFailBean.getData().getBank_name();
                                    url = jiaoYanFailBean.getSwitchURL();
                                    investment_Amount = jiaoYanFailBean.getData().getInvestment_Amount();


                                    showPopupWindow(btn_invest);
                                }
                            }

                            @Override
                            public void onError() {
                                // TODO Auto-generated method stub

                            }
                        };
                        volleryUtil.setHeaders("token", getToken());
                        volleryUtil.setHeaders("deviceId", getdeviceId());
                        volleryUtil.setRequestMethod(1);
                        volleryUtil.setShow(true);
                        volleryUtil.execute(V6iNewInvestCoupActivity2.this, Constant.URL + "/api/v6/invest/invests/valid?", params.toString());
                    }
                } else {
                    if (TextUtils.isEmpty(edit_zhitoumoney.getText().toString())) {
//            btn_invest.setBackground(getResources().getDrawable(R.drawable.v6_ud_bg_gray));
                        btn_invest.setEnabled(false);
                        btn_invest.setBackgroundResource(R.drawable.v6greybutton);
                    }
                    if (Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() < minAmount) {

                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);

                        if (minAmount < 10000) {
                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                            text_yuji.setText(minAmount + "元起投");
                            text_yuji.setTextColor(Color.parseColor("#ff0000"));
                            btn_invest.setEnabled(false);
                            btn_invest.setBackgroundResource(R.drawable.v6greybutton);
                        } else {
                            int a = minAmount / 10000;

                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                            text_yuji.setText(a + "万元起投");
                            text_yuji.setTextColor(Color.parseColor("#ff0000"));
                            btn_invest.setEnabled(false);
                            btn_invest.setBackgroundResource(R.drawable.v6greybutton);
                        }
                       /*
                        text_yuji.setText(minAmount + "万元起投");
                        tv_tishi.setText(minAmount + "万元起投");
                        layout_tishi.setVisibility(View.GONE);*/
                        tishi_coupon = true;

                    } else if (Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() > remainAmount) {

                        if (Double.valueOf(maxAmount).intValue() < 10000) {
                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);


                            text_yuji.setText("投资金额已超" + maxAmount.intValue());
                            tv_tishi.setText("投资金额已超" + maxAmount.intValue());
                            layout_tishi.setVisibility(View.GONE);
                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                        } else {
                            int a = Double.valueOf(maxAmount).intValue() / 10000;
                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);


                            text_yuji.setText("投资金额已超" + a + "万元");
                            tv_tishi.setText("投资金额已超" + a + "万元");
                            layout_tishi.setVisibility(View.GONE);
                            tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                        }


                        tishi_coupon = true;
                    } else if ((Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() - minAmount)
                            % increaseNum != 0 && remainAmount > minAmount) {

                        tv_tishi.setText("投资金额增量须为" + increaseNum + "的倍数");

                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                        text_yuji.setText("投资金额增量须为" + increaseNum + "的倍数");
                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                        tishi_coupon = true;
                    } else if (coupon_name.getText().toString().equals("未使用") && tishi_coupon && Integer.valueOf(couponCount) > 0) {
                        tishi_coupon = false;
                 /*   li_tishi.setVisibility(View.VISIBLE);
                    layout_tishi.setVisibility(View.VISIBLE);
                    tv_tishi.setText("亲，您还有未使用的福利哦!");*/
                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                        text_yuji.setText("亲，您还有未使用的福利哦!");
                        text_yuji.setTextColor(Color.parseColor("#ff0000"));
                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                        return;
                    } else if (getInvestNum() == 0 && MySharePreferenceUtil.get(V6iNewInvestCoupActivity2.this, "chanpin", "").equals("1")) {
                        showDialog();
                    } else {

                        AjaxParams params = new AjaxParams();
                        params.put("productId", loanid);
                        //金额传实际支付的

//                    int myIntentMoney = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() - Integer.valueOf(dikou);

                        if (myflag.equals("2")) {
                            int myIntentMoney = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() - Integer.valueOf(dikou);
                            params.put("amount", myIntentMoney + "");
                        } else {

                            params.put("amount", edit_zhitoumoney.getText().toString());
                        }
//                    params.put("amount", edit_zhitoumoney.getText().toString());
                        params.put("type", type);
                        params.put("useCurrentAmountToInvest", ishuo + "");

                        VolleryUtil volleryUtil = new VolleryUtil() {

                            @RequiresApi(api = VERSION_CODES.JELLY_BEAN)
                            @Override
                            public void onUpDate(JSONObject jsonObject) {
                                // TODO Auto-generated method stub
                                if (jsonObject.optInt("success") == 1) {
                                    LogUtils.e("加息券校验", jsonObject.toString());

                                    JiaoYanBean jiaoYanBean = new JiaoYanBean();
                                    Gson gson = new Gson();
                                    jiaoYanBean = gson.fromJson(jsonObject.toString(), JiaoYanBean.class);
                                    newProduceId = jiaoYanBean.getData().getProductId();
                                    Log.d(jsonObject.toString(), "444444444444");
                                    showPopupWindow(btn_invest);


                                } else {
                                    JiaoYanFailBean jiaoYanFailBean = new JiaoYanFailBean();
                                    Gson gson = new Gson();
                                    jiaoYanFailBean = gson.fromJson(jsonObject.toString(), JiaoYanFailBean.class);

                                    JSONObject user = jsonObject.optJSONObject("data");

                                    myamount2 = user.optDouble("amount");


                                    path = jiaoYanFailBean.getData().getPath();
                                    myamount = jiaoYanFailBean.getData().getAmount();
                                    bank_name = jiaoYanFailBean.getData().getBankName();
                                    card_no = jiaoYanFailBean.getData().getCard_no();
                                    type2 = jiaoYanFailBean.getData().getType();
                                    loan_id = jiaoYanFailBean.getData().getLoan_id();
                                    productId = jiaoYanFailBean.getData().getProductId();
                                    getBank_name = jiaoYanFailBean.getData().getBank_name();
                                    url = jiaoYanFailBean.getSwitchURL();
                                    investment_Amount = jiaoYanFailBean.getData().getInvestment_Amount();
                                    showPopupWindow(btn_invest);
                                }
                            }

                            @Override
                            public void onError() {
                                // TODO Auto-generated method stub

                            }
                        };
                        volleryUtil.setHeaders("token", getToken());
                        volleryUtil.setHeaders("deviceId", getdeviceId());
                        volleryUtil.setRequestMethod(1);
                        volleryUtil.setShow(true);
                        volleryUtil.execute(V6iNewInvestCoupActivity2.this, Constant.URL + "/api/v6/invest/invests/valid?", params.toString());

                    }
                }






              /*  if (minAmount > remainAmount) {

                    if (coupon_name.getText().toString().equals("未使用") && tishi_coupon) {
                        tishi_coupon = false;
                 *//*   li_tishi.setVisibility(View.VISIBLE);
                    layout_tishi.setVisibility(View.VISIBLE);
                    tv_tishi.setText("亲，您还有未使用的福利哦!");*//*
                        tv_v6_dexterity_pay_in_daotime.setVisibility(View.GONE);
                        text_yuji.setText("亲，您还有未使用的福利哦!");
                        return;
                    } else if (getInvestNum() == 0 && getisFingerPay() == 0) {
                        showDialog();
                    } else {
                        AjaxParams params = new AjaxParams();
                        params.put("productId", loanid);
                        //金额传实际支付的

//                    int myIntentMoney = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() - Integer.valueOf(dikou);

                        if (myflag.equals("2")) {
                            int myIntentMoney = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() - Integer.valueOf(dikou);
                            params.put("amount", myIntentMoney + "");
                        } else {

                            params.put("amount", edit_zhitoumoney.getText().toString());
                        }
//                    params.put("amount", edit_zhitoumoney.getText().toString());
                        params.put("type", type);
                        params.put("useCurrentAmountToInvest", ishuo + "");

                        VolleryUtil volleryUtil = new VolleryUtil() {

                            @RequiresApi(api = VERSION_CODES.JELLY_BEAN)
                            @Override
                            public void onUpDate(JSONObject jsonObject) {
                                // TODO Auto-generated method stub
                                if (jsonObject.optInt("success") == 1) {
                                    LogUtils.e("加息券校验", jsonObject.toString());

                                    JiaoYanBean jiaoYanBean = new JiaoYanBean();
                                    Gson gson = new Gson();
                                    jiaoYanBean = gson.fromJson(jsonObject.toString(), JiaoYanBean.class);
                                    newProduceId = jiaoYanBean.getData().getProductId();
                                    Log.d(jsonObject.toString(), "444444444444");
                                    showPopupWindow(btn_invest);


                                } else {
                                    JiaoYanFailBean jiaoYanFailBean = new JiaoYanFailBean();
                                    Gson gson = new Gson();
                                    jiaoYanFailBean = gson.fromJson(jsonObject.toString(), JiaoYanFailBean.class);

                                    path = jiaoYanFailBean.getData().getPath();
                                    myamount = jiaoYanFailBean.getData().getAmount();
                                    bank_name = jiaoYanFailBean.getData().getBankName();
                                    card_no = jiaoYanFailBean.getData().getCard_no();
                                    type2 = jiaoYanFailBean.getData().getType();
                                    loan_id = jiaoYanFailBean.getData().getLoan_id();
                                    productId = jiaoYanFailBean.getData().getProductId();
                                    getBank_name = jiaoYanFailBean.getData().getBank_name();
                                    url = jiaoYanFailBean.getSwitchURL();
                                    investment_Amount = jiaoYanFailBean.getData().getInvestment_Amount();
                                    showPopupWindow(btn_invest);
                                }
                            }

                            @Override
                            public void onError() {
                                // TODO Auto-generated method stub

                            }
                        };
                        volleryUtil.setHeaders("token", getToken());
                        volleryUtil.setHeaders("deviceId", getdeviceId());
                        volleryUtil.setRequestMethod(1);
                        volleryUtil.setShow(true);
                        volleryUtil.execute(V6iNewInvestCoupActivity.this, Constant.URL + "/api/v6/invest/invests/valid?", params.toString());

                    }
                }


                else {


                }*/


                break;

            case R.id.tv_mAgreement:
               /* intent = new Intent(V6iCoupActivity.this,
                        V4WebViewActivity.class);*/
                intent = new Intent(V6iNewInvestCoupActivity2.this, V4WebViewRegisterActivity.class);

                intent.putExtra("url", "/landing/mAgreement?app=true&appversion=true&productId=" + loanid);
                intent.putExtra("title", "认购协议");
                intent.putExtra("share", 1);
                startActivity(intent);
                break;
            case R.id.rl_dexterity:
                if (check_dexterity.isChecked()) {
                    img_ck_status.setVisibility(View.GONE);
                    check_dexterity.setChecked(false);
                } else {
                    img_ck_status.setVisibility(View.VISIBLE);
                    check_dexterity.setChecked(true);
                }
                ishuo = check_dexterity.isChecked();
//                myconmment();
                break;
            case R.id.check_mAgreement:
                if (check.isChecked()) {
                    btn_invest.setEnabled(false);
                    btn_invest.setBackgroundResource(R.drawable.btn_unclick);
                    check.setChecked(false);
                } else {
                    btn_invest.setEnabled(true);
                    btn_invest.setBackgroundResource(R.drawable.v6button);
                    check.setChecked(true);
                }
                break;

            case R.id.layout_investall:
            case R.id.text_yue:
            case R.id.text_quantou:
// 账户可用余额               tv_availableAmount
//minAmount 最低起投金额
//increaseNum 投资增量


                /*全投规则：
minAmount=1
                投资金额=(账户可用余额-起投金额)/递增金额 取整后 *递增金额+起投金额
*/
                //可投remainAmount
                //可用availableAmount
//起投金额minAmount
                //最大投资金额  <Double.valueOf(maxAmount).intValue()<remainAmount
                Log.d("账户可用余额", availableAmount + "");
                Log.d("项目起投资", minAmount + "");
                Log.d("项目剩余可投", remainAmount + "");
                Log.d("最大投资金额", maxAmount + "");
                if (availableAmount == 0) {
                    btn_invest.setEnabled(false);
                    btn_invest.setBackgroundResource(R.drawable.v6greybutton);
                }
                //账户可用余额 availableAmount   项目起投资 minAmount 项目剩余可投 remainAmount  最大投资金额 maxAmount

                if (minAmount >= remainAmount) {
                    //剩余可投

                    edit_zhitoumoney.setText(remainAmount + "");
                    edit_zhitoumoney.setSelection(edit_zhitoumoney.length());
                } else if (availableAmount <= minAmount && minAmount <= Double.valueOf(maxAmount).intValue() && Double.valueOf(maxAmount).intValue() <= remainAmount) {
                    //起投金额
                    edit_zhitoumoney.setText(minAmount + "");
                    edit_zhitoumoney.setSelection(edit_zhitoumoney.length());
                } else if (availableAmount <= minAmount && minAmount <= remainAmount && remainAmount <= Double.valueOf(maxAmount).intValue()) {
                    //起投金额
                    edit_zhitoumoney.setText(minAmount + "");
                    edit_zhitoumoney.setSelection(edit_zhitoumoney.length());
                } else if (minAmount <= Double.valueOf(maxAmount).intValue() && Double.valueOf(maxAmount).intValue() <= availableAmount && availableAmount <= remainAmount) {
                    //最大金额
                    edit_zhitoumoney.setText(Double.valueOf(maxAmount).intValue() + "");
                    edit_zhitoumoney.setSelection(edit_zhitoumoney.length());
                } else if (minAmount <= Double.valueOf(maxAmount).intValue() && Double.valueOf(maxAmount).intValue() <= remainAmount && remainAmount <= availableAmount) {
                    //最大金额
                    edit_zhitoumoney.setText(Double.valueOf(maxAmount).intValue() + "");
                    edit_zhitoumoney.setSelection(edit_zhitoumoney.length());
                }
//项目剩余可投
                //账户可用余额 availableAmount   项目起投资 minAmount 项目剩余可投 remainAmount  最大投资金额 maxAmount

                else if (remainAmount <= minAmount && remainAmount >= 10000) {

                    if (remainAmount <= remainAmount && remainAmount <= minAmount && minAmount <= Double.valueOf(maxAmount).intValue()) {
                        //项目剩余可投
                        edit_zhitoumoney.setText(remainAmount + "");
                        edit_zhitoumoney.setSelection(edit_zhitoumoney.length());
                    } else if (remainAmount <= minAmount && minAmount <= availableAmount && availableAmount <= Double.valueOf(maxAmount).intValue()) {
                        //项目剩余可投
                        edit_zhitoumoney.setText(remainAmount + "");
                        edit_zhitoumoney.setSelection(edit_zhitoumoney.length());
                    } else if (remainAmount <= minAmount && minAmount <= Double.valueOf(maxAmount).intValue() && Double.valueOf(maxAmount).intValue() <= availableAmount) {
                        //项目剩余可投
                        edit_zhitoumoney.setText(remainAmount + "");
                        edit_zhitoumoney.setSelection(edit_zhitoumoney.length());

                    } else if (remainAmount <= availableAmount && availableAmount <= minAmount && minAmount <= Double.valueOf(maxAmount).intValue()) {
                        //项目剩余可投
                        edit_zhitoumoney.setText(remainAmount + "");
                        edit_zhitoumoney.setSelection(edit_zhitoumoney.length());

                    }

                } else if (minAmount <= remainAmount && remainAmount <= availableAmount && availableAmount <= Double.valueOf(maxAmount).intValue()) {
                    //项目剩余可投
                    edit_zhitoumoney.setText(remainAmount + "");
                    edit_zhitoumoney.setSelection(edit_zhitoumoney.length());
                } else if (minAmount <= remainAmount && remainAmount <= Double.valueOf(maxAmount).intValue() && Double.valueOf(maxAmount).intValue() <= availableAmount) {
                    //项目剩余可投
                    edit_zhitoumoney.setText(remainAmount + "");
                    edit_zhitoumoney.setSelection(edit_zhitoumoney.length());
                } else if (maxAmount <= minAmount) {
                    //不规则的
                    edit_zhitoumoney.setText(minAmount + "");
                    edit_zhitoumoney.setSelection(edit_zhitoumoney.length());
                } else {
                    int a = Double.valueOf(availableAmount).intValue() - minAmount;
                    double b = (double) a / increaseNum;
                    Double f = Math.floor(b);
                    int c = f.intValue();
                    int d = c * increaseNum + minAmount;
                    Log.d(d + "", "3333333333333333333333333");

                    edit_zhitoumoney.setText(d + "");
                    edit_zhitoumoney.setSelection(edit_zhitoumoney.length());
                    text_yuji.setTextColor(Color.parseColor("#ff0000"));

                }


                break;

            case R.id.iv_cleardadta:
                edit_zhitoumoney.setText("");
                edit_zhitoumoney.setSelection(edit_zhitoumoney.length());
                break;

        }

    }

    PopupWindow popWindow2;

    private void showPopupWindow2(View parent) {
        if (popWindow2 == null) {
            View view2 = LayoutInflater.from(this)
                    .inflate(R.layout.pop_second2, null);
            //LayoutParams相当于一个Layout的信息包，它封装了Layout的位置、高、宽等信息。
            popWindow2 = new PopupWindow(view2, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
            initPop2(view2);
        }
        //设置动画效果
        popWindow2.setAnimationStyle(android.R.style.Animation_InputMethod);
        //获取popwindow焦点
        popWindow2.setFocusable(true);
        //设置popwindow如果点击外面区域，便关闭。
        popWindow2.setOutsideTouchable(true);
        popWindow2.setBackgroundDrawable(new BitmapDrawable());
        //实现软键盘不自动弹出,ADJUST_RESIZE属性表示Activity的主窗口总是会被调整大小，从而保证软键盘显示空间。
        popWindow2.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        //设置popwindow显示位置
        popWindow2.showAtLocation(parent, Gravity.CENTER, 0, 0);
    }

    public void initPop2(View view) {
        final LinearLayout layout_pop_first = (LinearLayout) view.findViewById(R.id.layout_pop_first);

        layout_pop_first.getBackground().setAlpha(175);
        layout_pop_first.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow2.dismiss();
                showPopupWindow4(layout_pop_first);
            }
        });
    }

    PopupWindow popWindow4;

    PopupWindow popWindow3;

    private void showPopupWindow3(View parent) {
        if (popWindow3 == null) {
            View view2 = LayoutInflater.from(this)
                    .inflate(R.layout.pop_third, null);
            //LayoutParams相当于一个Layout的信息包，它封装了Layout的位置、高、宽等信息。
            popWindow3 = new PopupWindow(view2, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
            initPop3(view2);
        }
        //设置动画效果
        popWindow3.setAnimationStyle(android.R.style.Animation_InputMethod);
        //获取popwindow焦点
        popWindow3.setFocusable(true);
        //设置popwindow如果点击外面区域，便关闭。
        popWindow3.setOutsideTouchable(true);
        popWindow3.setBackgroundDrawable(new BitmapDrawable());
        //实现软键盘不自动弹出,ADJUST_RESIZE属性表示Activity的主窗口总是会被调整大小，从而保证软键盘显示空间。
        popWindow3.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        //设置popwindow显示位置
        popWindow3.showAtLocation(parent, Gravity.CENTER, 0, 0);
    }

    public void initPop3(View view) {
        final LinearLayout layout_pop_third = (LinearLayout) view.findViewById(R.id.layout_pop_third);

        layout_pop_third.getBackground().setAlpha(175);
        layout_pop_third.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow3.dismiss();
//                showPopupWindow4(layout_pop_third);
                showPopupWindow4(layout_pop_third);
            }
        });

        Button tv_v6_dexterity_pay_in_updata = (Button) view.findViewById(R.id.tv_v6_dexterity_pay_in_updata);
        tv_v6_dexterity_pay_in_updata.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow3.dismiss();
//                showPopupWindow4(layout_pop_third);
                showPopupWindow4(layout_pop_third);
            }
        });
    }


    private void showPopupWindow4(View parent) {
        if (popWindow4 == null) {
            View view2 = LayoutInflater.from(this)
                    .inflate(R.layout.pop_fourth, null);
            //LayoutParams相当于一个Layout的信息包，它封装了Layout的位置、高、宽等信息。
            popWindow4 = new PopupWindow(view2, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
            initPop4(view2);
        }
        //设置动画效果
        popWindow4.setAnimationStyle(android.R.style.Animation_InputMethod);
        //获取popwindow焦点
        popWindow4.setFocusable(true);
        //设置popwindow如果点击外面区域，便关闭。
        popWindow4.setOutsideTouchable(true);
        popWindow4.setBackgroundDrawable(new BitmapDrawable());
        //实现软键盘不自动弹出,ADJUST_RESIZE属性表示Activity的主窗口总是会被调整大小，从而保证软键盘显示空间。
        popWindow4.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        //设置popwindow显示位置
        popWindow4.showAtLocation(parent, Gravity.CENTER, 0, 0);
    }

    public void initPop4(View view) {
        LinearLayout layout_pop_third = (LinearLayout) view.findViewById(R.id.layout_pop_fourth);

        layout_pop_third.getBackground().setAlpha(175);
        layout_pop_third.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow4.dismiss();
//                MySharePreferenceUtil.getBoolean(V6iNewInvestCoupActivity.this, SharePreferenceUtil.FIRST_OPEN2, true);

                MySharePreferenceUtil.put(V6iNewInvestCoupActivity2.this, "chanpin", "3");
//                MySharePreferenceUtil.clear(V6iNewInvestCoupActivity.this);
            }
        });

        Button button = (Button) view.findViewById(R.id.tv_v6_dexterity_pay_in_updata);
        button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow4.dismiss();
//                MySharePreferenceUtil.getBoolean(V6iNewInvestCoupActivity.this, SharePreferenceUtil.FIRST_OPEN2, true);
                MySharePreferenceUtil.put(V6iNewInvestCoupActivity2.this, "chanpin", "3");
//                MySharePreferenceUtil.clear(V6iNewInvestCoupActivity.this);
            }
        });
    }

    private PopupWindow popWindow;

    @RequiresApi(api = VERSION_CODES.JELLY_BEAN)
    private void showPopupWindow(View parent) {
        if (popWindow == null) {
            View view = LayoutInflater.from(this)
                    .inflate(R.layout.pop_select_photo2, null);
            //LayoutParams相当于一个Layout的信息包，它封装了Layout的位置、高、宽等信息。
            popWindow = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
            initPop(view);
        }
        //设置动画效果
        popWindow.setAnimationStyle(android.R.style.Animation_InputMethod);
        //获取popwindow焦点
        popWindow.setFocusable(true);
        //设置popwindow如果点击外面区域，便关闭。
        popWindow.setOutsideTouchable(true);
        popWindow.setBackgroundDrawable(new BitmapDrawable());
        //实现软键盘不自动弹出,ADJUST_RESIZE属性表示Activity的主窗口总是会被调整大小，从而保证软键盘显示空间。
        popWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        //设置popwindow显示位置
        popWindow.showAtLocation(parent, Gravity.CENTER, 0, 0);
    }

    int myamout;

    public String compare(BigDecimal val1, BigDecimal val2) {
        String result = "";
        if (val1.compareTo(val2) < 0) {
            result = "第二位数大！";
        }
        if (val1.compareTo(val2) == 0) {
            result = "两位数一样大！";
        }
        if (val1.compareTo(val2) > 0) {
            result = "第一位数大！";
        }
        return result;
    }

    Double string;

    private final String ACTION_NAME = "发送广播";

    private final String ACTION_NAME2 = "详情页面的跳转";
    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(ACTION_NAME)) {


                finish();
            }
        }

    };

    public void registerBoradcastReceiver() {
        IntentFilter myIntentFilter = new IntentFilter();
        myIntentFilter.addAction(ACTION_NAME);
        //注册广播
        registerReceiver(mBroadcastReceiver, myIntentFilter);
    }


    @RequiresApi(api = VERSION_CODES.JELLY_BEAN)
    public void initPop(View view) {
        ImageView iv_v4_pay_finish = (ImageView) view.findViewById(R.id.iv_v4_pay_finish);
        //点击popwindow消失

        View view_popdismiss = view.findViewById(R.id.pop_top);
        view_popdismiss.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
                popWindow = null;
            }
        });
        //余额
        TextView text_useyue = (TextView) view.findViewById(R.id.text_useyue);

        TextView text_investmoney = (TextView) view.findViewById(R.id.text_investmoney);

        DecimalFormat df = new DecimalFormat("#,###");
        String m = df.format(Double.valueOf(edit_zhitoumoney.getText().toString()).intValue());

        //        text_investmoney.setText(Regular.getDecimalFormatTwo(Double.valueOf(edit_zhitoumoney.getText().toString())).toString() + "元");
//        text_investmoney.setText(Regular.getDecimalFormatTwo(Double.valueOf(m)).toString() + "元");
        text_investmoney.setText(m + ".00" + "元");
        //带银行卡的
        LinearLayout layout_yinhangpay = (LinearLayout) view.findViewById(R.id.layout_yinhangpay);
        TextView text_yinhang = (TextView) view.findViewById(R.id.text_yinhang);

        //充值投资的按钮
        final Button btn_dexterity_invest = (Button) view.findViewById(R.id.btn_dexterity_invest);
        //空白
        final View layout_kongbai = view.findViewById(R.id.layout_kongbai);
        final LinearLayout layout_yinhang = (LinearLayout) view.findViewById(R.id.layout_yinhang);
        //银行名称
        TextView text_bangname = (TextView) view.findViewById(R.id.text_bangname);
        TextView bank_wei = (TextView) view.findViewById(R.id.bank_wei);

        TextView text_yinhang_name = (TextView) view.findViewById(R.id.text_yinhang_name);
        View lines_yinhang = view.findViewById(R.id.lines_yinhang);
        text_bangname.setText(getBank_name);
        //投资金额
        final BigDecimal b1 = new BigDecimal(edit_zhitoumoney.getText().toString());
        //账户可用余额
        final BigDecimal b2 = new BigDecimal(availableAmount);
        //抵扣的
        final BigDecimal b_dikou2 = new BigDecimal(dikou);
//b1-b2
        int compareTo = b1.compareTo(b2);
        int coupareto2 = compareTo - Double.valueOf(dikou).intValue();


        final TextView text_xiane = (TextView) view.findViewById(R.id.text_xiane);


        //余额小于投资金额


        if (b1.compareTo(b2) > 0 && Double.valueOf(text_shiji.getText().toString()).intValue() > availableAmount) {
            bank_wei.setText("(尾号:" + card_no.substring(card_no.length() - 4, card_no.length()) + ")");
            layout_yinhangpay.setVisibility(View.VISIBLE);
            BigDecimal b3 = new BigDecimal(edit_zhitoumoney.getText().toString());
            BigDecimal b4 = new BigDecimal(availableAmount);
            string = b3.subtract(b4).doubleValue();
            if (avaiableAmount2 < 1000) {
                text_useyue.setText(Regular.getDecimalFormatTwo(Double.valueOf(avaiableAmount3)) + "元");
            } else {

                DecimalFormat df2 = new DecimalFormat("#,###");
                String m1 = df2.format(avaiableAmount2);
                text_useyue.setText(m1 + ".00" + "元");

            }

            //账户可用余额

            final BigDecimal ketou_shengyu = new BigDecimal(availableAmount);
            //投资金额
            final BigDecimal zhanghukeyong = new BigDecimal(edit_zhitoumoney.getText().toString());
//            float ss = b1.subtract(b2).floatValue();
            Double yinhang = zhanghukeyong.subtract(ketou_shengyu).doubleValue();

//            text_yue.setText(avaiableAmount2 + "" + "元");
            if (myflag.equals("2")) {
                DecimalFormat df_yinhang = new DecimalFormat("#,###");
                if (Double.valueOf(myamount).intValue() < 1000) {
                    text_yinhang.setText(Regular.getDecimalFormatTwo(Double.valueOf(myamount)) + "元");
                } else {
                    BigDecimal b_investall = new BigDecimal(edit_zhitoumoney.getText().toString());//必须用字符串
                    BigDecimal b_yue = new BigDecimal(avaiableAmount3);
                    BigDecimal b = b_investall.subtract(b_yue);//会输出0.1


                    BigDecimal b_dikou = new BigDecimal(dikou);

                    BigDecimal b_dikouhou = b.subtract(b_dikou);//会输出0.1
//
//                    double n = myamount2;
                    DecimalFormat df2 = new DecimalFormat("#,###.00");
                    String yue = df2.format(b_dikouhou);

                    text_yinhang.setText(yue + "元");
                }


          /*      double n = myamount2;
                DecimalFormat df2 = new DecimalFormat("#,###.00");
                String yue = df2.format(n);

*/
            } else {
                if (Double.valueOf(myamount).intValue() < 1000) {
//                    text_yinhang.setText(Regular.getDecimalFormatTwo(Double.valueOf(myamount)) + "元");
                   /* DecimalFormat df_yinhang = new DecimalFormat("#,###");

                    BigDecimal b_investall = new BigDecimal(edit_zhitoumoney.getText().toString());//必须用字符串
                    BigDecimal b_yue = new BigDecimal(avaiableAmount3);
                    BigDecimal b = b_investall.subtract(b_yue);//会输出0.1

                    double n=b.doubleValue();

//
//                    double n = myamount2;
                    DecimalFormat df2 = new DecimalFormat("#,###.00");
                    String yue = df2.format(n);
*/
                    text_yinhang.setText(Regular.getDecimalFormatTwo(Double.valueOf(myamount)) + "元");
                } else {
                    DecimalFormat df_yinhang = new DecimalFormat("#,###");

                    BigDecimal b_investall = new BigDecimal(edit_zhitoumoney.getText().toString());//必须用字符串
                    BigDecimal b_yue = new BigDecimal(avaiableAmount3);
                    BigDecimal b = b_investall.subtract(b_yue);//会输出0.1
//
//                    double n = myamount2;
                    DecimalFormat df2 = new DecimalFormat("#,###.00");
                    String yue = df2.format(b);

                    text_yinhang.setText(yue + "元");


                }


            }


            layout_yinhang.setVisibility(View.VISIBLE);
            layout_kongbai.setVisibility(View.GONE);
//            text_yinhang.setText(Regular.getDecimalFormatTwo(yinhang) + "元");
            AjaxParams params = new AjaxParams();
            params.put("bankName", bank_name + "");//1

            VolleryUtil3 volleryUtil = new VolleryUtil3() {
                @Override
                public void onUpDate(JSONObject jsonObject) {

                    Gson gson1 = new Gson();
                    LimitBean limitBean = new LimitBean();
                    limitBean = gson1.fromJson(jsonObject.toString(), LimitBean.class);
                    limitByOnce = limitBean.getData().getLimitByOnce();
                    limitByDay = limitBean.getData().getLimitByDay();
                    limitByMonth = limitBean.getData().getLimitByMonth();
                    int once = Double.valueOf(limitByOnce).intValue() / 10000;
                    int day = Double.valueOf(limitByDay).intValue() / 10000;
                    int monty = Double.valueOf(limitByMonth).intValue() / 10000;
                    btn_dexterity_invest.setText("充值并投资");
                    text_xiane.setText("单笔限额" + once + "万元/" + "单日限额" + day + "万元" + "单月限额" + monty + "万元");
                }


                @Override
                public void onError() {

                }


            };
//                    vollery.OnButtonListener(V6iNewInvestCoupActivity.this);
            volleryUtil.setShow(true);
            volleryUtil.setRequestMethod(0);

            volleryUtil.execute(V6iNewInvestCoupActivity2.this,
                    Constant.URL + "api/v2/getLLSupportBankLimit?",
                    params.toString());


        } else {

            int myIntentMoney = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() - Integer.valueOf(dikou);
            if (myflag.equals("2")) {
                DecimalFormat df2 = new DecimalFormat("#,###");
                String m1 = df2.format(Double.valueOf(myIntentMoney).intValue());

                text_useyue.setText(m1 + ".00" + "元");
//                text_useyue.setText(Regular.getDecimalFormatTwo(Double.valueOf(myIntentMoney)) + "元");
            } else {
                DecimalFormat df2 = new DecimalFormat("#,###");
                String m1 = df2.format(Double.valueOf(edit_zhitoumoney.getText().toString()).intValue());
                text_useyue.setText(m1 + ".00" + "元");
            }
            btn_dexterity_invest.setText("立即支付");
            layout_yinhang.setVisibility(View.GONE);
            layout_kongbai.setVisibility(View.VISIBLE);
            layout_yinhangpay.setVisibility(View.VISIBLE);
            lines_yinhang.setVisibility(View.GONE);
            text_yinhang_name.setText("");
            text_yinhang.setText("");
        }
        iv_v4_pay_finish.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
                popWindow = null;
            }
        });
        btn_dexterity_invest.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                Log.d("3333333333333", getToken());
                String newtoken = getToken();
                try {
                    newtoken = URLEncoder.encode(newtoken, "UTF-8");
//                        myurl1= URLEncoder.encode(myurl1, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                }


                if (b1.compareTo(b2) > 0 && Double.valueOf(text_shiji.getText().toString()).intValue() > availableAmount) {
                    AjaxParams params = new AjaxParams();
                    int myIntentMoney = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() - Integer.valueOf(dikou);

                    if (myflag.equals("2")) {
//                        intent.putExtra("money", myIntentMoney + "");
                        params.put("amount", myamount + "");
                    } else {
                        params.put("amount", myamount + "");
                    }
//                    params.put("amount", string + "");//1
                    params.put("path", path);//1
                    params.put("bankName", bank_name);
                    params.put("card_no", card_no);//1
                    params.put("investment_Amount", investment_Amount);//1
                    params.put("loan_id", loan_id);//1
                    params.put("client", "android");
                    params.put("token", newtoken);//1
                    params.put("type", type2);
//                //1   params.put("bankName", bank_name);         params.put("bank_name", getBank_name);
                    if (myflag.equals("1")) {
//                        params.put("coupon_id", reward_id);
                        params.put("coupon_id", reward_id);
//                        intent.putExtra("red_id", reward_id);cardID
                        //红包
                        params.put("coupon_type", "giftId");
//                        params.put("bankName", "giftId");
//                        params.put("bank_name", bankName);//1

                    } else if (myflag.equals("2")) {
//折扣券
                        params.put("coupon_id", cardId);
//                        params.put("cardID", cardId);
                        params.put("coupon_type", "cardId");
//                        params.put("bank_name", bankName);//1
//                        params.put("bankName",bank_name);
                    } else if (myflag.equals("3"))
//              &coupon_type=&
                    {
                        params.put("coupon_id", "raisingratesId");
//                        params.put("coupon_id", reward_id);
                        params.put("cardID", reward_id);
//                        params.put("bankName",bank_name);
                    } else {
                   /*     params.put("coupon_id", "");
                        params.put("coupon_type", "");*/

//                        params.put("bank_name", bank_name);//1

                    }
                    NewVolleryUtil newVolleryUtil = new NewVolleryUtil() {
                        @Override
                        public void onError() {
                        }

                        @Override
                        public void onUpDate(String jsonObject) {
                            Log.d(jsonObject, "4444444444444444");
                            Intent intent = new Intent(V6iNewInvestCoupActivity2.this, NewV6WebviewChild.class);
//                            intent.putExtra("url", url); coupid  还有红包的
//                            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            intent.putExtra("url", jsonObject.toString());
                            startActivity(intent);
                            popWindow.dismiss();
                            popWindow = null;
//                            finish();
                        }

                    };

                    newVolleryUtil.setShow(true);
                    newVolleryUtil.setRequestMethod(1);

                    newVolleryUtil.setHeaders("deviceId", getdeviceId());

            /*        newVolleryUtil.execute(V6iNewInvestCoupActivity.this,
                            Constant.URL + "hpay/v3/h5recharge?",
                            params.toString());*/
                    newVolleryUtil.execute(V6iNewInvestCoupActivity2.this, Constant.URL + "hpay/v3/h5recharge?", params.toString());
                } else {
            /*        int c = V6NewZhiTouDexterityPayInActivity.count_julu;

                    int d = V6iNewInvestCoupActivity.count;
                    int m = c + d;*/
                    int c = V6NewZhiTouDexterityPayInActivity.count_julu;

                    int d = V6iNewInvestCoupActivity2.count_julu;
                    int m = c + d;
              /*      Toast.makeText(V6iNewInvestCoupActivity.this, c +
                            "", Toast.LENGTH_SHORT).show();*/
                    if (getisFingerPay() == 1 && m < 5) {
                        onFingerprintClick(1);
                    } else if (m == 5) {
                        Intent intent = new Intent(V6iNewInvestCoupActivity2.this, PayActivity.class);
                        intent.putExtra("flagRedpack", flagred);
                        intent.putExtra("rate", rate);
                        intent.putExtra("qixian", month);
                        intent.putExtra("minAmount", minAmount);
                        intent.putExtra("isZhi", 0);
                        if (payPass) {
                            intent.putExtra("setPass", 0);
                        } else {
                            intent.putExtra("setPass", 1);
                            intent.putExtra("openfingerPay", 1);
                        }
                        intent.putExtra("flagFresh", flagFresh);
                        intent.putExtra("productId", loanid);
                        intent.putExtra("title_tpye", type);
                        intent.putExtra("increaseNum", increaseNum);
                        intent.putExtra("remainAmount", remainAmount);
                        intent.putExtra("myflag", myflag);
                        intent.putExtra("title", tv_title.getText().toString());
                        try {
                            int myIntentMoney = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() - Integer.valueOf(dikou);
                            if (myflag.equals("2")) {
                                intent.putExtra("money", myIntentMoney + "");
                            } else {
                                intent.putExtra("money", edit_zhitoumoney.getText().toString() + "");
                                layout_liquan.setVisibility(View.INVISIBLE);
                                text_title.setVisibility(View.GONE);
                                layout_dikou.setVisibility(View.INVISIBLE);
                            }

                        } catch (Exception e) {

                        }

                        if (myflag.equals("1")) {
                            intent.putExtra("red_id", reward_id);
                        }

                        if (myflag.equals("2")) {
//                        intent.putExtra("money", shijie + "");
//                        intent.putExtra("money", myIntentMoney + "");
                            intent.putExtra("cardId", cardId);
                        } else {
                            intent.putExtra("raisingratesId", reward_id);
                            intent.putExtra("money", edit_zhitoumoney.getText().toString() + "");
                        }


                        intent.putExtra("flagcoupon", resultcoupon);
                        intent.putExtra("useCurrentAmountToInvest", ishuo);
                        startActivityForResult(intent, 0);

                        overridePendingTransition(R.anim.right_in,
                                R.anim.right_in);
                    } else {

                        Intent intent = new Intent(V6iNewInvestCoupActivity2.this, PayActivity.class);
                        intent.putExtra("flagRedpack", flagred);
                        intent.putExtra("rate", rate);
                        intent.putExtra("qixian", month);
                        intent.putExtra("minAmount", minAmount);
                        intent.putExtra("isZhi", 0);
                        if (payPass) {
                            intent.putExtra("setPass", 0);
                        } else {
                            intent.putExtra("setPass", 1);
                            intent.putExtra("openfingerPay", 1);
                        }
                        intent.putExtra("flagFresh", flagFresh);
                        intent.putExtra("productId", loanid);
                        intent.putExtra("title_tpye", type);
                        intent.putExtra("increaseNum", increaseNum);
                        intent.putExtra("remainAmount", remainAmount);
                        intent.putExtra("myflag", myflag);
                        intent.putExtra("title", tv_title.getText().toString());
                        try {
                            int myIntentMoney = Double.valueOf(edit_zhitoumoney.getText().toString()).intValue() - Integer.valueOf(dikou);
                            if (myflag.equals("2")) {
                                intent.putExtra("money", myIntentMoney + "");
                            } else {
                                intent.putExtra("money", edit_zhitoumoney.getText().toString() + "");
                                layout_liquan.setVisibility(View.INVISIBLE);
                                text_title.setVisibility(View.GONE);
                                layout_dikou.setVisibility(View.INVISIBLE);
                            }

                        } catch (Exception e) {

                        }

                        if (myflag.equals("1")) {
                            intent.putExtra("red_id", reward_id);
                        }

                        if (myflag.equals("2")) {
//                        intent.putExtra("money", shijie + "");
//                        intent.putExtra("money", myIntentMoney + "");
                            intent.putExtra("cardId", cardId);
                        } else {
                            intent.putExtra("raisingratesId", reward_id);
                            intent.putExtra("money", edit_zhitoumoney.getText().toString() + "");
                        }


                        intent.putExtra("flagcoupon", resultcoupon);
                        intent.putExtra("useCurrentAmountToInvest", ishuo);
                        startActivityForResult(intent, 0);

                        overridePendingTransition(R.anim.right_in,
                                R.anim.right_in);
                    }


                }


            }

        });

    }


    @Override
    public void onConfirm() {
        // TODO Auto-generated method stub
        Intent intent = null;
        switch (mAlertDialog.getType()) {

            case "bindcard":
                intent = new Intent(V6iNewInvestCoupActivity2.this,
                        V6WebviewChild.class);
                intent.putExtra("url", Constant.URL + "h5/account/bankcard/bind/view?app=true&token=");
                intent.putExtra("title", "智投宝");
                startActivity(intent);
                break;
            case "password":
                intent = new Intent(V6iNewInvestCoupActivity2.this,
                        V6WebviewChild.class);
                intent.putExtra("url", Constant.URL + "h5/setTraPwd?app=true&token=");
                intent.putExtra("title", "智投宝");
                startActivity(intent);
                break;
            case "ceping":
                Intent intent0 = null;

                intent0 = new Intent(V6iNewInvestCoupActivity2.this, WebViewActivity.class);
                intent0.putExtra("url", "h5/assess/answer" + "?app=true&token=");
                // intent0.putExtra("url",
                // "h5/assess/index?showHeader=1"+"?app=true&token=");
                // intent0.putExtra("flag", 1);
                // intent2.putExtra("url",
                // "/h5/messageCenter?app=true&token="+getToken());
                intent0.putExtra("share", 1);
                intent0.putExtra("titleview", 1);
                intent0.putExtra("title", "风险测评");
                startActivity(intent0);
                break;
        }
    }

    @Override
    public void onCancle() {
        // TODO Auto-generated method stub

    }
}
